您好,尝试过类似以前有效的方法
driver.find_element_by_xpath("//*[@id="loginForm"]/div/div[1]/input").send_keys("abhishek.gupta1608@toppr.in")
但现在出现错误
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="inputs"]//input[@name="email"]"}
最佳答案
您可以尝试使用名称:
driver.find_element_by_name("email").send_keys("abhishek.gupta1608@toppr.in")
如果您想引入 webDriverWait :
wait = WebDriverWait(driver,10)
wait.until(EC.element_to_be_clickable((By.NAME, 'email'))).send_keys("abhishek.gupta1608@toppr.in")
请注意,您必须导入这些:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
更新1:
您在 iframe 中,您必须将 Web 驱动程序的焦点切换到默认内容,然后才能与其交互:
driver.switch_to.default_content()
wait.until(EC.element_to_be_clickable((By.NAME, 'email'))).send_keys("abhishek.gupta1608@toppr.in")
关于python - 如何使用 Selenium 和 Python 将文本发送到电子邮件字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610098/