[英]Can't click the login button on this website by using Python Selenium
[英]Can't click on *Login as* button python selenium
试图点击这个按钮
试过:
driver.find_element(By.XPATH, '//*[@id="signup_with_facebook"]/button').click()
错误:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
试过:
button = driver.find_element(By.XPATH, '//*[@id="signup_with_facebook"]/button')
ActionChains(driver).move_to_element(
button
).click(
button
).perform()
错误:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLButtonElement] has no size and location
这个怎么做?
代码:
driver = webdriver.Chrome(executable_path='chromedriver')
driver.get('https://www.myheritage.com/deep-nostalgia')
driver.find_element(By.XPATH, '//*[@id="masterPageHeader"]/div/div[3]/div/div[2]/div[1]/div[2]/a[1]/span').click()
driver.implicitly_wait(10)
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="signup_with_facebook"]/button'))).click()
错误:
selenium.common.exceptions.TimeoutException: Message:
有两个具有相同@id
的按钮:第一个在 signupContainer 中(您尝试单击的那个),第二个在 loginContainer 中。 您需要 select 第二个。 为此,请使用此 XPath:
'//div[@id="loginContainer"]//div[@id="signup_with_facebook"]/button'
看起来您正试图在页面仍未完全呈现时单击此元素。
尝试添加一个显式等待以等待此元素可见性,然后再单击它,如下所示:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="signup_with_facebook"]/button'))).click()
PS 我无法验证您在此处使用的定位器以及整个代码的正确性,因为您没有共享所有代码。
UPD
添加代码后,我可以看到:
'//*[@id="signup_with_facebook"]/button'
不是唯一的,它应该是固定的。driver = webdriver.Chrome(executable_path='chromedriver')
driver.get('https://www.myheritage.com/deep-nostalgia')
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='user_strip_end']//a[@class='user_strip_item user_strip_item_1']"))).click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#loginContainer button.facebook_login_button'))).click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.