我在https://www.mister-auto.com上
我想选择菜单中具有属性data-selenium='link_front_generic'
所以我尝试了以下代码:
driver.findElement(By.xpath("(.//*[@data-selenium='link_front_generic'])[1]")).click();
但是,找不到该项目
我有一个例外: org.openqa.selenium.ElementNotVisibleException:元素不可见
答案 0 :(得分:0)
该元素不可见,因为它位于菜单包装中,并且未被触发。
您可以尝试以下代码。
Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.xpath("//a[text()='Pièces auto']"));
actions.moveToElement(menu);
WebElement subMenu = driver.findElement(By.xpath("//a[@title='Plaquette de frein']"));
actions.moveToElement(subMenu);
actions.click().build().perform();