I am trying to execute below Selenium Web driver script, But I am getting org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may n
Finally this worked for me. Element is not currently visible and so may not be interacted with.
Initially it was like test was successful only 2 of 5 times. Was not sure how it was working sometimes and others not.
Worked by reducing the security settings in IE. Enable all activeX controls. Enable scripts and IFRAMES also. Some of these will warn to put computer at risk, but it was the only solution I had. Introduce Explicit wait by using presenceOfElementLocated instead of visibilityOfElementLocated at every point where page load takes time.
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='campaignListTable']"))); /*examining the xpath for a search
box*/
driver.findElement(By.xpath("//*[@id='campaignListTable']")).sendKeys("TEXT"); /*enter text in search
box*/
I guess you are trying to click on hyperlinks, if you are getting 'ElementNotVisibleException' this means that elements might be hidden. Does it take long time for the elements with locator 'a.uiv2-add-button.a2c' to render on the UI after you select a Category from the left panel? If yes than interaction wiith non visible elements will always throw 'ElementNotVisibleException'
Just put the thread to sleep for some mil seconds
Thread.sleep(5000);
WebElement zoneName=driver.findElement(By.xpath("//*[@id=\"zoneName\"]"));
zoneName.sendKeys("kandy");
Not sure what your requirement is. But, couple of things to keep in mind.
if you know for sure the element is not hidden then you can use the following wait for the element to be visible
new WebDriverWait(Driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible("your selector");
To handle it , you can use explicit wait function in selenium to locate element. Most of the time it works.
For some browsers it happens that once mouse hover action is performed, but the menu list disappear quickly before Selenium identify the next sub menu item. In that case it is better to use perform()
action on the main menu to hold the menu list till the time Selenium identify the sub menu item and click on it.
Here
WebElement xWL = driver.findElement(By.xpath("x path text"));
Actions xAct = new Actions(driver);
Instead of this:
xAct.moveToElement(xWL).build().perform();
Below code will resolve the "element not visible" issue
xAct.moveToElement(xWL);
xAct.click();
xAct.perform();