我是 selenium webdriver 的新手,我正在努力在网页上找到一个按钮,因为它的 Id 不断变化,并且没有其他属性可用于识别该元素。请参阅下面的代码。 有人可以看看这段代码并帮助我如何识别这个按钮元素。
最佳答案
您应该尝试使用xPath
,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 1000);
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xPath("//div[contains(@class, 'header-navigation__cta-buttons-wrapper')]/a[contains(@class, 'cta-buttons__link--button-1')]")));
el.click();
确保该元素不在框架内..
希望对你有帮助..:)
关于java - Webdriver:查找并单击隐藏元素,其中 id 不断变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37677460/