[英]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 × 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.