[英]"ElementNotInteractableException" and "NoSuchElementException" while trying to login in to Proton mail using Selenium(Python)
I am tryin to automate the process of creating a proton mail account.我正在尝试自动化创建质子邮件帐户的过程。 My python code runs fine until I reach the point where it has to enter the username in the sign up process.
我的 python 代码运行良好,直到我到达必须在注册过程中输入用户名的地步。 Here is a photo of the html code of the site - photo of Proton sign up page and it's html code , the site allows me to type password with selenium but its not allowing me to enter the username.
这是该站点的 html 代码的照片 - Proton 注册页面的照片,它是 html 代码,该站点允许我使用 Z8E00596AD8DE2213FF8F8D8478D5362C 输入密码,但不允许我输入用户名I have tried selecting the input tag and its parent div.
我尝试选择输入标签及其父 div。
The below code is for selecting the input tag.下面的代码用于选择输入标签。
pmail_user_data = generator.generate_protonmail_user_data()
driver.set_page_load_timeout(20)
username_input = driver.find_element(By.XPATH, "//*[@id='username']")
username_input.click()
time.sleep(0.5)
username_input.send_keys(pmail_user_data[2])
With this code I end up with:-有了这段代码,我最终得到:-
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
And the code below is when is selected the parent div.下面的代码是何时选择父 div。
pmail_user_data = generator.generate_protonmail_user_data()
driver.set_page_load_timeout(20)
username_input = driver.find_element(By.XPATH, "/html/body/div[1]/label/div[2]/div/div[1]")
username_input.click()
time.sleep(0.5)
username_input.send_keys(pmail_user_data[2])
With this I end up with:-有了这个,我最终得到: -
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/label/div[2]/div/div[1]"}
I have tried various methods like ActionChains, WebDriverWait, driver.implicitly_wait().我尝试过各种方法,例如 ActionChains、WebDriverWait、driver.implicitly_wait()。 But nothing seems to work for me.
但似乎没有什么对我有用。 Any answer is much appreciated, Thank you in advance.
任何答案都非常感谢,在此先感谢您。
To send a character sequence to the Email field within Protonmail you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :要将字符序列发送到Protonmail中的Email字段,您需要为element_to_be_clickable()引入WebDriverWait并且您可以使用以下任一定位器策略:
Using CSS_SELECTOR :使用CSS_SELECTOR :
driver.get("https://account.protonmail.com/login") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#username"))).send_keys("KAMI@D.KAI")
Using XPATH :使用XPATH :
driver.get("https://account.protonmail.com/login") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='username']"))).send_keys("KAMI@D.KAI")
Note : You have to add the following imports:注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:浏览器快照:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.