如何切换到一个框架,并在弹出点击了使用网络驱动程序(硒 - Java的)? [英] How do I switch to a Frame and click on the pop up using web driver (Selenium - Java)?

查看:214
本文介绍了如何切换到一个框架,并在弹出点击了使用网络驱动程序(硒 - 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>

我知道我应该切换到机架上,以做任何操作在框架中。

I understand that I should switch to frame in order to do to any operations in the frame.

我在那里的问题是:


  • 如何切换到帧? (我无法找出正确的
    定位在switch语句中使用(driver.switchto()。框架(什么
    应该GO HERE)))?

  • How do I switch to frame? (I am not able to figure out the right locator to use in the switch statement (driver.switchto().frame("WHAT SHOULD GO IN HERE")))?

有没有一种方法来检查,如果当我浏览到一个新的存在,这架
网页每一次?

Is there a way to check if this frame exists when i navigate to a new page every time?

由于一吨的帮助....
迈克

Thanks a ton for the help.... Mike

推荐答案

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

If the frame is the only frame on the page then you can go with

driver.switch.frame(0); //不是一个很好的,虽然

driver.switch.frame(0); //not a good way though

您可以使用XPath或任何识别您的iframe,然后使用如下

you can use xpath or anything to identify your iframe and then use that as below

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

元素标识应上述unique..the的XPath仅仅是一个way..but它可能不是你的整个HTML unique..depends。

The element identification should be unique..the xpath given above is just one way..but it might not be unique..depends on your entire html.

希望有所帮助。

这篇关于如何切换到一个框架,并在弹出点击了使用网络驱动程序(硒 - Java的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆