简体   繁体   中英

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. You need to select second one. To do so use this 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.
UPD
After you added your code I can see that:

  1. You should add an explicit wait before clicking the login button.
  2. You should improve the login button locator.
  3. You should not mix explicit waits with implicitly waits.
  4. The locator you are using '//*[@id="signup_with_facebook"]/button' is not unique, it should be fixed.
    This should work better:
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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM