Chetan_K Chetan_K - 3 months ago 15
Java Question

Unable to click on a sub value of a tab, getting 'element not visible' exception in Selenium

Trying to click on the 'E-Commerce Demo Site' in the 'DEMO SITES' tab in 'http://toolsqa.com/' website using the below mentioned ways. But unable to click on it. Kindly help me on this issue.

Code1:

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.linkText("E-Commerce Demo Site"))));
driver.findElement(By.linkText("E-Commerce Demo Site")).click();


Code2:

driver.findElement(By.cssSelector("#main-nav > li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-has-children.menu-item-17611.dt-mega-menu.mega-auto-width.mega-column-1.has-children > ul > li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-21575.dt-mega-parent.wf-1.first.level-arrows-on")).click();


Code3:

WebElement subNav = driver.findElement(By.className("sub-nav"));
List < WebElement > subNavValues = subNav.findElements(By.tagName("li"));

subNavValues.get(0).click();

Answer
     Actions ac;
 ac = new Actions(dr);
ac.MoveToElement(dr.FindElement(By.LinkText("DEMOSITES"))).Perform();

Then use any of the following xpaths to click on the submenu:

1."//span[contains(text(),'E-Commerce Demo Site')]"

2."//a[@href='http://store.demoqa.com']"

dr.findelement(By.xpath(xpath)).click();
Comments