Reputation: 78
I'm using Selenium to click the "Become A Member" button from this link: https://www2.hm.com/en_us/register.
Here is the HTML of the button: https://i.sstatic.net/Pjeu3.png
I have exhausted all other answers on this site: I have tried to find this element using XPath, CSS Selector, waited for element to be clickable, visible, etc. all but to no avail.
Here is my current code that accepts all the cookies (since I thought that was the problem) and then tries to click on the "Become a Member" button
try:
# Accepts cookies
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input[id='onetrust-accept-btn-handler']"))).click()
# Clicks the register button
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input[data-testid='submitButton']"))).click()
except:
print("Driver waited too long!")
driver.quit()
Does anyone know what I can do to fix this issue? Thank you!
Upvotes: 1
Views: 590
Reputation: 29382
to click on Become A Member
button you are using input[data-testid='submitButton']
which is almost correct but it's not input tag, it's a button.
See the HTML here :
<button class="CTA-module--action__3hGPH CTA-module--medium__dV8ar CTA-module--primary__3hPd- CTA-module--fullWidth__1GZ-5 RegisterForm--submit__2Enwx" data-testid="submitButton" type="submit"><span>BECOME A MEMBER</span></button>
so changing input[data-testid='submitButton']
to button[data-testid='submitButton']
did the trick and it worked.
Sample code : -
try:
# Accepts cookies
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input[id='onetrust-accept-btn-handler']"))).click()
# Clicks the register button
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-testid='submitButton']"))).click()
except:
print("Driver waited too long!")
driver.quit()
Upvotes: 1