JohnMax
JohnMax

Reputation: 1

How to insert text within the element through Selenium and Java

Can someone give me a hint to locate an element in selenium?

Where is what I tried to select

WebElement  hello =  driver.findElement(By.className("input-box"));

Error from Eclipse:

Can't find symbol 'GetGraphicsResetStatus'.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .input\-box

Thank you again.

original html

<div data-v-7d31c51a="" data-v-126e1ccf="" class="input-box"><textarea data-v-7d31c51a="" placeholder="inputhere~" maxlength="500" autofocus="autofocus" class="textarea" style="height: 60px;"></textarea><div data-v-7d31c51a="" class="indicator" style="bottom: -30px; right: 100px;"><span data-v-7d31c51a="" class="">0</span>/<span data-v-7d31c51a="">500</span></div></div>

Error from trying WebElement hello = driver.findElement(By.className("textarea"));

Can't find symbol 'GetGraphicsResetStatus'. Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .textarea For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'

Adding my jar file and my codes

enter image description here

Upvotes: 0

Views: 330

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193078

The element is a dynamic element, so to send a character sequence to the desired element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.input-box>textarea.textarea[placeholder^='inputhere']"))).sendKeys("JohnMax");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='input-box']/textarea[@class='textarea' and starts-with(@placeholder, 'inputhere')]"))).sendKeys("JohnMax");
    

Upvotes: 1

KunduK
KunduK

Reputation: 33384

You have consider wrong class name for the inputbox.Your class should be.

WebElement  hello =  driver.findElement(By.className("textarea"));

Upvotes: 0

Sameer Arora
Sameer Arora

Reputation: 4507

Try the xpath:

 WebElement hello =  driver.findElement(By.xpath("//div[@placeholder='inputhere~']"));

Upvotes: 1

Related Questions