无法使用 webdriver 切换到 iframe
unable to switch to iframe using webdriver
我无法切换到 iframe 并对其进行控制。
这是 DOM:
<iframe class="ze_area">
#document
<html><head><link type="text/css" rel="stylesheet" href="https://css.zohostatic.com/ze/v86/css/zeditor.min.css"><style type="text/css">.ze_body{font-family:Verdana,arial,Helvetica,sans-serif;font-size:13px;} table{font-size:100%} .MsoNormal{margin: 0px}</style><style>ol.code li { word-wrap: break-word; } ol.code li pre,span,p,div {white-space: normal !important; }</style>
</head>
<body class="ze_body">
</body></html>
<iframe>
我正在尝试使用此代码 运行
WebElement filebug=driver.findElement(By.id("fileabugnew"));
filebug.click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement filebug_subject=driver.findElement(By.id("fileabug_subject"));
filebug_subject.sendKeys("web erp : test failed to search for web title");
driver.switchTo().frame(0);
WebElement
filebug_content=driver.findElement(By.className("//body[@class='ze_body']"));
filebug_content.sendKeys("erp content. the test is failed");
WebElement click_to_assign=driver.findElement(By.xpath("//span[text()='Not
Assigned']"));
click_to_assign.click();
WebElement
type_to_assign=driver.findElement(By.xpath("//div[@class='select2-drop
searchableselect2 select2-with-searchbox select2-drop-
active']//input[@class='select2-input']"));
type_to_assign.sendKeys("shashank.choursia");
driver.findElement(By.id("submitbug")).click();
您需要找到要切换到的 iframe 的索引。 driver.switchTo().frame(0);表示您正在切换到索引为“0”的 iframe。有关详细信息,请参阅 How to identify and switch to the frame in selenium webdriver when frame does not have id
或
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
// your action here
driver.switchTo().defaultContent();
最初,您需要导航到该用途的父框架:
driver.switchto().defaultContent();
完成后,您可以导航到您的网络元素基于索引的框架。
driver.switchTo().frame(i);
其中 'i' 是从“0”开始的索引。
希望这对您有所帮助,如有疑问请告诉我。
我无法切换到 iframe 并对其进行控制。 这是 DOM:
<iframe class="ze_area">
#document
<html><head><link type="text/css" rel="stylesheet" href="https://css.zohostatic.com/ze/v86/css/zeditor.min.css"><style type="text/css">.ze_body{font-family:Verdana,arial,Helvetica,sans-serif;font-size:13px;} table{font-size:100%} .MsoNormal{margin: 0px}</style><style>ol.code li { word-wrap: break-word; } ol.code li pre,span,p,div {white-space: normal !important; }</style>
</head>
<body class="ze_body">
</body></html>
<iframe>
我正在尝试使用此代码 运行
WebElement filebug=driver.findElement(By.id("fileabugnew"));
filebug.click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement filebug_subject=driver.findElement(By.id("fileabug_subject"));
filebug_subject.sendKeys("web erp : test failed to search for web title");
driver.switchTo().frame(0);
WebElement
filebug_content=driver.findElement(By.className("//body[@class='ze_body']"));
filebug_content.sendKeys("erp content. the test is failed");
WebElement click_to_assign=driver.findElement(By.xpath("//span[text()='Not
Assigned']"));
click_to_assign.click();
WebElement
type_to_assign=driver.findElement(By.xpath("//div[@class='select2-drop
searchableselect2 select2-with-searchbox select2-drop-
active']//input[@class='select2-input']"));
type_to_assign.sendKeys("shashank.choursia");
driver.findElement(By.id("submitbug")).click();
您需要找到要切换到的 iframe 的索引。 driver.switchTo().frame(0);表示您正在切换到索引为“0”的 iframe。有关详细信息,请参阅 How to identify and switch to the frame in selenium webdriver when frame does not have id
或
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
// your action here
driver.switchTo().defaultContent();
最初,您需要导航到该用途的父框架:
driver.switchto().defaultContent();
完成后,您可以导航到您的网络元素基于索引的框架。
driver.switchTo().frame(i);
其中 'i' 是从“0”开始的索引。
希望这对您有所帮助,如有疑问请告诉我。