gpt4 book ai didi

Selenium : handling popups

转载 作者:行者123 更新时间:2023-11-28 20:50:37 26 4
gpt4 key购买 nike

我在使用 selenium 脚本处理默认弹出窗口时遇到错误。

代码如下:

@Test
public void handlePop() {

WebElement pop1 = driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_PopupCTRLMain_imgNext']"));
pop1.click();

WebElement pop2 = driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_PopupCTRLMain_Image2']"));
pop2.click();
}

以下是我在运行代码时遇到的错误:

org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='ctl00_ContentPlaceHolder1_PopupCTRLMain_Image2']

最佳答案

您可能会添加 if 条件来检查是否显示弹出,例如

try { 
if (pop1.getSize > 0) {
pop1.click();
} catch (e)
}

关于 Selenium : handling popups,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48793208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com