我正在尝试登录Quora网站。在我的本地机器上它运行完美。
但是在 SSH 服务器上(DigitalOcean 上的 droplet)——不,我得到了InvalidElementStateException
我试图通过 来关注元素send_keys(Keys.NULL)
,并得到了 ElementNotVisibleException
这是代码:
driver.get("https://www.quora.com/")
print("Logging...")
# gets email and password from json
with open('config.json') as f:
login_data = json.load(f)
email = login_data['email']
password = login_data['pass']
time.sleep(3)
email_field_xpath = "//div[@class='form_column']/input[@name='email']"
password_field_xpath = "//div[@class='form_column']/input[@name='password']"
# webdriver's going to wait max 10 seconds for email's field, password field, login button to display
email_field_element = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_xpath(email_field_xpath))
password_field_element = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_xpath(password_field_xpath))
email_field_element.send_keys(Keys.NULL)
email_field_element.clear()
email_field_element.send_keys(email)
password_field_element.send_keys(Keys.NULL)
password_field_element.clear()
password_field_element.send_keys(password)
login_button_xpath = "//input[@value='Login']"
# wait till element is clickable
login_button_element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, login_button_xpath)))
login_button_element.click()
print("Logged In.")