'WebDriver' object has no attribute 'switch_to_alert'
时间: 2023-10-10 14:04:54 浏览: 215
webdriver不能启动浏览器,报module ‘selenium.webdriver’ has no attribute”问题解决办法
5星 · 资源好评率100%
这个错误"Traceback (most recent call last): File "D:\pcode\26.py", line 7, in <module> driver.switchTo().frame("iframeResult");AttributeError: 'WebDriver' object has no attribute 'switchTo'"是由于使用了错误的方法名导致的。正确的方法名是'switch_to_alert'而不是'switchTo'。你需要将代码中的'switchTo'替换为'switch_to_alert'。
以下是修改后的代码:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
driver=webdriver.Firefox()
waitdd = WebDriverWait(driver, 30);
driver.get("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert");
driver.switch_to.frame("iframeResult");
driver.find_element(By.xpath("//html/body/button")).click();
waitdd.until(ExpectedConditions.alertIsPresent());
driver.switch_to.alert.accept();
driver.switch_to.default_content();
希望这能帮助到你解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
阅读全文