我无法切换到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();