我有一个循环,它通过改变一些设置并保存它们并尝试返回到相同的设置页面来与页面进行交互,第二次尝试时,它找不到ID为nav-hamburger-menu的元素,尽管设置改变后它没有改变。有什么问题吗
代码如下:
for(int i = 0; i < 3; i++) {
System.out.print(" Prasisuko ");
WebElement openMenu = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[id='nav-hamburger-menu']")));
openMenu.click();
WebElement changeLang = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#hmenu-icp-language.hmenu-item")));
changeLang.click();
WebElement enUsRadioButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[name='lop'][value='en_US']")));
System.out.print(enUsRadioButton.isSelected());
// // Check if the "en_US" radio button is checked
if (enUsRadioButton.isSelected()) {
WebElement deDERadioButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[name='lop'][value='de_DE']")));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", deDERadioButton);
} else {
enUsRadioButton.click();
}
WebElement spanElement = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("span#icp-currency-dropdown-selected-item-prompt")));
spanElement.click();
WebElement aElement = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#icp-currency-dropdown_19[data-value*='EUR']")));
aElement.click();
WebElement saveSettingsButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.a-button-input")));
saveSettingsButton.click();
}
我试过很多方法来找到那个元素,但同样的事情,在第二次尝试它失败了
1条答案
按热度按时间ajsxfq5m1#
您的问题需要更多细节。当你说“and on second try it can't find element with id nav-hamburger-menu,“
当你通过开发工具和脚本运行验证失败并出现异常时,你能看到一个元素吗?或者你的元素html值被修改了,你无法使用相同的定位器来唯一地标识它?
您也可以在设置更新之前和之后发布html片段。