简体   繁体   English

如何使用python修复Selenium Web驱动程序``异常错误''

[英]How to fix selenium web driver 'exception error' with python

I Am creating a bot to create email accounts in bulk using Python with selenium web driver on chrome browser with proton mail as the email service. 我正在创建一个机器人,以在Chrome浏览器上使用带有硒网络驱动程序的Python和质子邮件作为电子邮件服务来批量创建电子邮件帐户。 I am having issues prefilling the form fields when the test gets to the form page to fill out your email address etc. and getting this error on the terminal. 当测试到达表单页面以填写您的电子邮件地址等时,我在预填表单字段时遇到问题,并且在终端上收到此错误。

raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: 引发TimeoutException(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:

I Have tried increasing the wait time with no luck. 我尝试增加等待时间,但是没有运气。 I am using send_keys to prefill the fields but no luck. 我正在使用send_keys来预填充字段,但没有运气。 The tests shown in the code below all work except for the last one where it hits the form page to prefill the email username. 下方代码中显示的测试均有效,除了最后一个命中表单页面以预填充电子邮件用户名的测试。

from selenium import webdriver
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys


url = 'https://protonmail.com/'

driver = webdriver.Chrome(
'/Users/[MYNAME]/Downloads/chromedriver')
driver.get(url)


signUp = WebDriverWait(driver, 5).until(
    EC.visibility_of_element_located((By.XPATH, '//* . 
  [@href="signup"]')))
    signUp.click()
    panel = WebDriverWait(driver, 5).until(
    EC.element_to_be_clickable((By.CLASS_NAME, 'panel-heading')))
panel.click()
plan = WebDriverWait(driver, 2).until(
    EC.element_to_be_clickable((By.ID, 'freePlan')))
plan.click()

username = WebDriverWait(driver, 3).until(
    EC.element_to_be_clickable((By.ID, 'username')))
username.click()
username.send_keys('usernameForUSer')

I expect the username field to prefill. 我希望用户名字段能预填。

There is an iframe which blocking to access the element.You need to switched to iframe first. 有一个iframe阻止访问该元素。您需要先切换到iframe Try following code. 尝试以下代码。

WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, 'iframe.top')))
username = WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.ID, 'username')))
username.click()
username.send_keys('usernameForUSer') 

Browser Snapshot: 浏览器快照:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM