我正在尝试单击带有硒的登录按钮(chrome驱动程序,--headless)。 问题是登录按钮前面有一个元素。即使某个元素挡在了路上,也可以单击按钮吗?
我的Python脚本看起来像这样:
pirkciau_driver=webdriver.Chrome(crm_path, chrome_options=options)
pirkciau_driver.get(login_url)
elem = pirkciau_driver.find_element_by_id("email")
elem.clear()
elem.send_keys(x['pirkciau']['username'])
elem = pirkciau_driver.find_element_by_id("passwd")
elem.clear()
elem.send_keys(x['pirkciau']['password'])
elem = pirkciau_driver.find_element_by_id("SubmitLogin")
elem.click()
答案 0 :(得分:2)
尝试如下使用JavaScript Click
:
pirkciau_driver=webdriver.Chrome(crm_path, chrome_options=options)
pirkciau_driver.get(login_url)
elem = pirkciau_driver.find_element_by_id("email")
elem.clear()
elem.send_keys(x['pirkciau']['username'])
elem = pirkciau_driver.find_element_by_id("passwd")
elem.clear()
elem.send_keys(x['pirkciau']['password'])
elem = pirkciau_driver.find_element_by_id("SubmitLogin")
driver.execute_script("arguments[0].click();", elem);
答案 1 :(得分:1)
很少有这样做的方法:
elem.send_keys(Keys.RETURN)
答案 2 :(得分:1)
您可以使用
pirkciau_driver.execute_script('arguments[0].click()', elem)
单击当前与另一个元素重叠的按钮,但不会模拟真实的类似用户的行为...如果要进行测试,最好等到接收到单击而不是“登录”按钮的元素变为不可见ExplicitWait和until_not(EC.visibility_of_element_located())
或until(EC.invisibility_of_element_located())