【发布时间】:2017-03-03 18:26:02
【问题描述】:
- 0-415 构建已通过
416-550 失败了
-
以下定位器用于工作:
public @FindBy(xpath = ".//*[@id='menu']/ul//a[@href='/driving-experiences']") WebElement link_DrivingExperiences; 现在它突然停止工作,我尝试使用绝对 XPATH 并且有效;我试图避免,我打算使用动态定位器。
-
我的点击方式:
public void waitAndClickElement(WebElement element) throws InterruptedException { boolean clicked = false; int attempts = 0; while (!clicked && attempts < 3) { try { this.wait.until(ExpectedConditions.elementToBeClickable(element)).click(); System.out.println("Successfully clicked on the WebElement: " + "<" + element.toString() + ">"); clicked = true; } catch (Exception e) { System.out.println("Unable to wait and click on WebElement, Exception: " + e.getMessage()); Assert.fail("Unable to wait and click on the WebElement, using locator: " + "<" + element.toString() + ">"); } attempts++; }}
【问题讨论】:
-
什么是“停止工作”?它现在给
NoSuchElementException还是不触发任何事件?我尽量避免使用 XPath 并改用 CssSelector。通常,您可以以更短的方式找到元素,DOM 中的更改不会使用 CssSelector 轻易破坏您的测试。 -
考虑到提供
HTML你的XPath似乎没问题。分享异常日志 -
请将 HTML 发布为文本而不是图像。它使潜在的回答者更容易使用和阅读。你试过像
By.linkText("Driving")或By.cssSelector("a[href='/driving-experiences']")这样简单的东西吗?您可能会看到嵌套太深的 XPath 的影响。没有前后HTML等就很难说了。
标签: java selenium selenium-webdriver webdriver