<iframe id="vacancy_department_requirements_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 100px; display: block;">
<!DOCTYPE html>
<html>
我在使用webdriver自动化应用程序时切换iframe时遇到问题。有三个texteditor。当我检查元素然后在相同的iframe ID时,id会发生变化。所以我无法在帧之间切换。
我写了以下代码: -
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("vacancy_job_requirements_ifr"));
WebElement element2 = driver.findElement(By.cssSelector("body"));
JavascriptExecutor executor3 = (JavascriptExecutor)driver;
executor3.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML2</h1>'", element2);
*/
/*wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("vacancy_job_description_ifr"));
WebElement element3 = driver.findElement(By.cssSelector("body"));
JavascriptExecutor executor4 = (JavascriptExecutor)driver;
executor4.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML2 gf</h1>'", element3);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("vacancy_department_requirements_ifr"));
WebElement element4 = driver.findElement(By.cssSelector("body"));
JavascriptExecutor executor5 = (JavascriptExecutor)driver;
executor5.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML3 gf</h1>'", element4);*/
但上面的代码给出了以下错误:
"Timed out after 120 seconds waiting for frame to be available: vacancy_job_description_ifr'
请建议。
答案 0 :(得分:0)
您可以按索引切换帧,即driver.switchTo()。frame()。找到帧数并通过提供其索引值切换到帧。
参考链接(How to switch between frames in Selenium WebDriver using Java)
答案 1 :(得分:0)
使用driver.switchTo()。frame(driver.findElement(By.id(“pvacancy_department_requirements_ifr”)));