[英]Can't click on *Login as* button python selenium
Trying to click on this button试图点击这个按钮
Tried:试过:
driver.find_element(By.XPATH, '//*[@id="signup_with_facebook"]/button').click()
Error:错误:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Tried:试过:
button = driver.find_element(By.XPATH, '//*[@id="signup_with_facebook"]/button')
ActionChains(driver).move_to_element(
button
).click(
button
).perform()
Error:错误:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLButtonElement] has no size and location
How to do this?这个怎么做?
Code:代码:
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()
Error:错误:
selenium.common.exceptions.TimeoutException: Message:
There are two buttons with the same @id
: first one inside signupContainer (the one that you're trying to click), second - in loginContainer.有两个具有相同@id
的按钮:第一个在 signupContainer 中(您尝试单击的那个),第二个在 loginContainer 中。 You need to select second one.您需要 select 第二个。 To do so use this XPath:为此,请使用此 XPath:
'//div[@id="loginContainer"]//div[@id="signup_with_facebook"]/button'
Looks like you are trying to click this element while the page is still not fully rendered.看起来您正试图在页面仍未完全呈现时单击此元素。
Try adding an Explicit Wait to wait for this element visibility before clicking it, something like this:尝试添加一个显式等待以等待此元素可见性,然后再单击它,如下所示:
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 I can't validate the locator you are using here and the entire code correctness since you didn't share all your code. PS 我无法验证您在此处使用的定位器以及整个代码的正确性,因为您没有共享所有代码。
UPD UPD
After you added your code I can see that:添加代码后,我可以看到:
'//*[@id="signup_with_facebook"]/button'
is not unique, it should be fixed.您使用的定位器'//*[@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.