[英]Why has my XPATH locator suddenly stopped working?
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++; }
}
您可以選擇鏈接文本,從長期來看,很可能不會更改
//a[text()='Driving'] or
//a[contains(text(),'Driving')]
如果案例中的鏈接文本“ Driving”包含前導或尾隨空格,請使用案例2。
嘗試類似...
public @FindBy(xpath = "//a[contains(@class, 'toplevellink') and contains(@href, 'driving-experiences')]"))
干杯,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.