gpt4 book ai didi

java - 如何保持下拉菜单处于 Activity 状态并单击 selenium 中 iframe 下可用的子菜单?

转载 作者:行者123 更新时间:2023-12-02 09:51:49 24 4
gpt4 key购买 nike

要求:单击“操作”下拉列表中的子菜单,如下所示,并且每个元素位于不同的 iframe 中

Selenium 3.141

操作 > 菜单 > 子菜单 > 单击子菜单项

操作 - iframe1 > 菜单 - iframe2 > 子菜单 - iframe3

所有这些框架都在另一个框架内,iframe3 位于 iframe2 内,iframe2 位于 iframe1 内

当我点击“操作”时,下拉菜单会打开,当我尝试点击其他操作时,下拉菜单会关闭,因此脚本失败,并出现未找到可点击的异常元素

driver.findElement(By.xpath("//*[contains(@title, 'Actions')]")).click();
switchToFrame("listHidden");
driver.findElement(By.id("PMCProjectCreateMenu")).click();
switchToFrame("submenu");
driver.findElement(By.xpath("//*[contains(label,'Create New...')]"));

or

//in below case how to switch to iframes
Actions action = new Actions(driver);
WebElement actionMenu= driver.findElement(By.xpath("//*[contains(@title, 'Actions')]"));
action.moveToElement(actionMenu).moveToElement(driver.findElement(By.id("PMCProjectCreateMenu"))).moveToElement(driver.findElement(By.xpath("//*[contains(label,'Create New...')]"))).click().build().perform();```

Expected : To navigate through actions > menu > submenu and click on submenu
Actual: Clicks on actions and fails to continue


最佳答案

尝试使用 WebDriverWait 和预期条件 frameToBeAvailableAndSwitchToIt,而不是调用 switchToFrame(),以便驱动程序等待足够的时间来显示新的内部 iframe ...

WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("listHidden");

还有一些说法是切换后需要点击主体,但我没有测试过。(发现这个 here

关于java - 如何保持下拉菜单处于 Activity 状态并单击 selenium 中 iframe 下可用的子菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56273464/

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