Selenium.common.exceptions.TimeoutException While Clicking On A Button Using Expected_conditions Presence_of_element_located In Selenium Python
Solution 1:
I wish I could tell you that this works 100% of the time (it doesn't) but perhaps it will get you a bit closer. I think one of the problems is that when you login the settings for Account are not open and visible (at least that is always the case for me) and you have to first click on the Account selection at the left to reveal the Mobil settings. Unfortunately, even that does not work 100% of the time, at least not with the following code (I am using basic element click calls). But I offer this up for what it's worth:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
try:
driver.implicitly_wait(10) # wait up to 10 seconds before calls to find elements time out
driver.get('https://www.nike.com/member/settings')
input('pausing for login ...') # to allow manual login
driver.get('https://www.nike.com/member/settings')
elem = driver.find_element_by_xpath('/html/body/div[3]/div/div[6]/div[1]/div[1]/div') # Account settings
elem.click()
elem = driver.find_element_by_xpath('/html/body/div[3]/div/div[6]/div[2]/div[2]/div/form/div[2]/div[5]/div/div/div/div[2]/button')
elem.click()
finally:
input('pausing for inspection') # to allow inspection
driver.quit()
Solution 2:
To click on the element with text as Hinzufügen instead of presence_of_element_located()
you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label='Mobilnummer hinzufügen']"))).click()
Using
XPATH
and aria-label attribute:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label='Mobilnummer hinzufügen']"))).click()
Using
XPATH
and innerText attribute:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(., 'Hinzufügen')]"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Solution 3:
I was quite new to coding, I still am, and I just wanted to create a little script for myself. Also I was quite unexperienced with XPaths. I recommend everybody who stumbles upon this issue, to read through this article.
I used this XPath, instead:
//div[@class="mex-mobile-input"]/div/div/div[2]/button
Post a Comment for "Selenium.common.exceptions.TimeoutException While Clicking On A Button Using Expected_conditions Presence_of_element_located In Selenium Python"