根据上面的代码,我试图在Selenium中找到并执行对元素的操作。
Actions action = new Actions(driver);
对元素进行控制
WebElement we = driver.findElement(By.xpath("//li[@class='static dynamic-children']/a[@href='/activa/gentex/ee/#']/span[@class='additional-background']"));
action.moveToElement(we).build().perform();
WebDriverWait wait = new WebDriverWait(driver, 50);
// wait for the edit employee information to appear
wait.until(ExpectedConditions.presenceOfElementLocated(By
.xpath("//a[contains(@class,'selected')]/span[@class='additional-background']/span[@class='menu-item-text']")));
// action.moveToElement(driver.findElement(By.xpath("//div[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).build().perform();
// action.click(driver.findElement(By.xpath("//div[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li/ul/li[2]/a/span/span"))).perform();
将控制移动到子菜单项以单击它。
driver.findElement(By.xpath("//a[contains(@class,'selected')]/span[@class='additional-background']/span[@class='menu-item-text']")).click();
答案 0 :(得分:0)
您的xpath似乎不正确,请检查以下正确的代码:
Actions action = new Actions(driver);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement Mainmenu= driver.findElement(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]"));
action.moveToElement(Mainmenu).build().perform();
WebElement submenu1 = driver.findElement(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span"));
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='zz1_TopNavigationMenuV4']/div/ul/li/ul/li[1]/ul/li[1]/a/span/span")));
submenu1.click();
我将鼠标悬停在主菜单上:My Benefit Resources然后点击子菜单:Enrollment。上面的代码应该适合你。
答案 1 :(得分:0)
要阅读标签,请尝试以下方法:
<span>xyz</span>
你可以试试这个: 将xpath重新构造为
//span[contains(.,'xyz')]
应该有所帮助。