【问题标题】:How do I switch to a Frame and click on the pop up using web driver (Selenium - Java)?如何使用 Web 驱动程序(Selenium - Java)切换到框架并单击弹出窗口?
【发布时间】:2012-09-25 09:55:16
【问题描述】:
<iframe height="0" frameborder="0" width="500" scrolling="no" style="position: absolute; top: 185.5px; left: 460.5px; height: 357px; width: 500px; z-index: 10002; border: medium none; background-color: rgb(255, 255, 255); opacity: 0;" src="/foresee/shim.gif" alt="Survey Invitation Helper Window - Please Ignore">
<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height;">
<style>
<title>shim.gif (GIF Image, 1&nbsp;×&nbsp;1 pixels)</title>
</head>
<body>
<img src="https://www3-qan.tivo.com/foresee/shim.gif" alt="https://www3-qan.tivo.com/foresee/shim.gif">
</body>
</html>
</iframe>
<div class="fsrwin" style="position: absolute; width: 500px; z-index: 10005; left: 460.5px; top: 185.5px; opacity: 1;">
<div class="innerwin">
<div class="fsr_top">
<div class="fsr_middle">
<div class="fsr_closeBody fsr_closeButtons">
<button id="decline" class="fsr_closeSticky fsr_button fsr_decline">No thanks</button>
<button id="accept" class="fsr_closeSticky fsr_button fsr_accept">Yes, I'll give feedback</button>
</div>

我知道我应该切换到框架以执行框架中的任何操作。

我的问题是:

  • 如何切换到框架? (我无法弄清楚正确的 在 switch 语句中使用的定位器 (driver.switchto().frame("WHAT 应该进入这里")))?

  • 当我导航到一个新的框架时,有没有办法检查这个框架是否存在 每次都翻页?

非常感谢您的帮助.... 迈克

【问题讨论】:

  • @Zohaib:如果我觉得帖子有用,我会点击“是”。我如何接受答案。请帮忙。谢谢

标签: java selenium automated-tests ui-automation selenium-webdriver


【解决方案1】:

如果框架是页面上唯一的框架,那么您可以使用

driver.switch.frame(0); //这不是一个好方法

您可以使用 xpath 或任何东西来识别您的 iframe,然后按如下方式使用它

driver.switch.frame(driver.findElementByXpath("//iframe[contains(@src,'forsee')]"))

元素标识应该是唯一的..上面给出的 xpath 只是一种方式..但它可能不是唯一的..取决于您的整个 html。

希望对您有所帮助..

【讨论】:

  • 谢谢...我如何接受这个答案作为正确答案...我没有接受答案选项...谢谢...。
【解决方案2】:

通过 selenium ide 记录您的测试,并根据您的意愿将其导出到 selenium rc junit 或 testng。

会有一行像selenium.selectFrame(frameName)..在driver.switchToFrame(frameName)中使用相同的框架名。

【讨论】:

    猜你喜欢
    • 2018-07-15
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    相关资源
    最近更新 更多