繁体   English   中英

如何切换到框架并使用Web驱动程序(Selenium-Java)单击弹出窗口?

[英]How do I switch to a Frame and click on the pop up using web driver (Selenium - Java)?

<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(“此处应有什么内容”)))?

  • 每次导航到新页面时,是否可以检查此框架是否存在?

非常感谢您的帮助。

如果该框架是页面上的唯一框架,则可以使用

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

要么

您可以使用xpath或其他任何方法来识别您的iframe,然后按以下方式使用

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

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

希望有帮助。

通过硒离子记录您的测试,并根据您的需要将其导出到硒rc unit或testng中。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM