gpt4 book ai didi

java - 无法在 Selenium Webdriver 中选择框架

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:10:58 24 4
gpt4 key购买 nike

我知道这个问题已经被问过好几次了,但我一直没能弄清楚我的问题。我正在尝试选择“fraHeader”框架,但我得到的只是“无法定位元素”错误。我在 Java 中使用 Webdriver

我尝试过的事情:

  1. 使用 driver.findElement 找到框架,然后使用 driver.switchTo 切换到它 - 这是行不通的。我一直收到“无法定位元素”。

  2. 我试过使用 xpath、id 和名称来定位框架,但都没有用。

  3. 使用 Selenium IDE 记录操作并导出到 Java - 这给了我://错误:捕获异常 [错误:不支持的命令 [selectFrame |标题 | ]]
  4. 插入 mydriver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);以防代码运行得太快。这也无济于事。

这是我的网站代码:

    <meta http-equiv="expires" content="-1">
<meta http-equiv= "pragma" CONTENT="no-cache">
<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<meta name="robots" content="noindex,nofollow">
<link rel="P3Pv1" href="/w3c/p3p.xml">
<script type="text/javascript" src="/scripts/frameset.js"></script>
</head>
<frameset id='masterFrameset' rows='130,*,25' border='0' framespacing='0' frameborder='no' onload=''>
<frame name='fraHeader' noresize scrolling='no' marginwidth='0' marginheight='0' frameborder='no' src='/header-default.jsp'>
<frame name='fraBody' noresize scrolling='auto' marginwidth='0' marginheight='0' frameborder='no' src='/control/store/login'>
<frame name='fraFooter' noresize scrolling='no' marginwidth='0' marginheight='0' frameborder='no' src='/footer-default.jsp'>
</frameset>
</html>
&#0149;

我是 Selenium 的新手,感谢任何帮助。

最佳答案

也许您需要使用 WebDriverWait 来等待框架可见。您尝试的是隐式等待,显式等待可能值得一试。

WebDriverWait wait = new WebDriverWait(driver, 60);  
WebElement iframe = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("masterFrameset"));
driver.switchTo().frame(iframe);

driver.switchTo().frame("masterFrameset");

或者如果 iframe 是第一个?

driver.switchTo().frame(0);

关于java - 无法在 Selenium Webdriver 中选择框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28467276/

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