Reputation: 21
xpath found in chrome/firefox console, but not found by selenium ? any suggestion ?
And try chropath(chrome plugin) none of them work:
Java code both way:
List<WebElement> Elements = driver.findElements(By.xpath("/html/body/div[2]/div/div[1]/div[2]/div[2]/div[1]/div/div[3]/div[1]/div[4]/div[2]/textarea"));
new WebDriverWait(driver, 30).until(ExpectedConditions.elementToBeClickable(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[3]/div[1]/div[4]/div[2]/textarea[1]"))).sendKeys("testing");
Here is what the Selenium give:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: /html1/body1/div2/div1/div1/div2/div2/div1/div1/div3/div1/div[4]/div2/textarea1 (tried for 30 second(s) with 500 MILLISECONDS interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:82) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231) at message.hello.main(hello.java:148) Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: /html1/body1/div2/div1/div1/div2/div2/div1/div1/div3/div1/div[4]/div2/textarea1 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' System info: host: 'daviss-MacBook-Pro.local', ip: '2600:1010:b06c:96a7:d93d:6b6e:3c3d:3826%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '10.0.1'
Would like to put some text into the text area. if this possible with selenium ?
Also confirm that the page doesn't have any thing to do with iframe
Upvotes: 0
Views: 2683
Reputation: 21
Just refresh the page :)
I had the same issue. The absolute xpath was valid and could be found on developer console on Firefox as well as Chrome. However, WebDriver was only able to find the element on Chrome and was not able to find it on Firefox. I tried many things but nothing worked. Finally I decided to refresh the page using WebDriver and, voilla, after that the same code started working in Firefox and continued to work in Chrome. So just insert the below line above the code where you are trying to locate the element using the absolute xpath.
driver.navigate().refresh();
Upvotes: 2
Reputation: 36
A couple of reasons/options, you can try here-
sendKeys()
sendKeys()
.Upvotes: 0
Reputation: 392
Try with javascript executor to send the value to the WebElement:
WebElement wb = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/div[2]/div[2]/div[1]/div/div[3]/div[1]/div[4]/div[2]/textarea"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='(222)222-2222';", wb);
Upvotes: 0
Reputation: 26
Try using array list if you need to use List of element.
List<WebElement> Elements = driver.findElements(By.xpath("/html/body/div[2]/div/div[1]/div[2]/div[2]/div[1]/div/div[3]/div[1]/div[4]/div[2]/textarea"));
ArryaList <String> elementList = new ArryaList<>();
for (WebElement ele : Elements){
elementList.add(ele)
}
new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOf(elementList.get(0));
elementList.get(0).click();
Upvotes: 0
Reputation: 33384
Try this below XPath
it should work.
driver.findElement(By.xpath("//textarea[@class='textarea']")).sendKeys("testing");
OR
driver.findElement(By.xpath("//textarea[@placeholder='inputthere~']")).sendKeys("testing");
In case if it gives error.Please check any iframe
is avaiable? if avaialble then you have to switched to iframe first.
driver.switchTo().frame("Frame-Name")
Hope this help you!
Upvotes: 1