当我尝试单击附件中显示的“C”链接时,我遇到了一个奇怪的问题。请遵守红色标记的链接说明。
我在下面尝试过,但没有帮助。
WebElement ele=driver.findElement(By.xpath("//ul[@class='whp-rolodex']/li[contains(.,'C')]"));
ele.click();
然后我尝试使用操作,但没有帮助
Actions action=new Actions(driver);
action.moveToElement(ele).click().perform();
action.click().perform(); //this also didnt help
然后尝试使用 JavaScriptExecutor,这也没有帮助
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
我在这些点击之前保留了 ele.isDisplayed() ,并且在所有地方都显示 true。
有人可以帮助我哪里出错了,有没有更好的方法。
使用 FF 40、selenium webdriver 2.47
最佳答案
这是因为你的xpath错误。当您尝试在“li”标签中查找 c 时,C 包含在“a”标签中。
使用像这样的xpath
//ul[@class='whp-rolodex']/li[3]/a[contains(.,'C')]
关于java - 如何在 Selenium 中单击对象或触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32442648/