Reputation: 444
I encountered following error, during UI Testing.
org.openqa.selenium.WebDriverException: Element not found or not visible for xpath: (//div[@class='popupContent'])[last()]/div/div/div/div/div[2]/div/table/tbody Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z' System info: host: 'x', ip: '172.25.x.x', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60' Driver info: driver.version: unknown
Can anyone let me know what has caused this error?
Thank you
Upvotes: 0
Views: 1890
Reputation: 193338
This error message...
org.openqa.selenium.WebDriverException: Element not found or not visible for xpath: (//div[@class='popupContent'])[last()]/div/div/div/div/div[2]/div/table/tbody
...implies that the WebDriver instance was unable to find any element as per the Locator Strategy you have used.
The reason for the error Element not found or not visible can be either of the following :
<iframe>
tag.The solution to address NoSuchElementException can be either of the following :
Adopt a Locator Strategy which uniquely identifies the desired WebElement. You can take help of the Developer Tools (Ctrl+Shift+I or F12) and use Element Inspector.
Here you will find a detailed discussion on how to inspect element in selenium3.6 as firebug is not an option any more for FF 56?
Use executeScript()
method to scroll the element in to view as follows :
WebElement elem = driver.findElement(By.xpath("element_xpath"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", elem);
Here you will find a detailed discussion on Scrolling to top of the page in Python using Selenium
Incase element is having the attribute style="display: none;", remove the attribute through executeScript()
method as follows :
WebElement element = driver.findElement(By.xpath("element_xpath"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('style')", element)
element.sendKeys("text_to_send");
To check if the element is within an <iframe>
traverse up the HTML to locate the respective <iframe>
tag and switchTo()
the desired iframe through either of the following methods :
driver.switchTo().frame("frame_name");
driver.switchTo().frame("frame_id");
driver.switchTo().frame(1); // 1 represents frame index
Here you can find a detailed discussion on Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?.
If the element is not present/visible in the HTML DOM immediately, induce WebDriverWait with ExpectedConditions set to proper method as follows :
To wait for presenceOfElementLocated :
new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
To wait for visibilityOfElementLocated :
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
To wait for elementToBeClickable :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
Apart from the above mentioned reasons/solutions, one of your major issue is the incompatibility between the version of the binaries you are using as follows:
So there is a clear mismatch between the JDK v8u60 and the Selenium Client v3.13.0 which you are using.
@Test
.Upvotes: 1
Reputation: 1101
Essentially what the stacktrace tells you:
Element not found or not visible for xpath
Most likely, you have provided an valid (syntax-wise), but incorrect xpath.
A good way of debugging (on Chrome, find your equivalent if using another browser):
If nothing shows up and you get 0 hits with that xpath, it means that the xpath is incorrect.
Upvotes: 1