1

I'm trying to build a test, but I can't seem to find (and then click) on an element with a unique name that's in the page HTML.

It works up until here:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

driver = webdriver.Chrome()
driver.get("https://www.hallmark.nl/kaarten/verjaardag-man/")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='https://www.hallmark.nl:443/kaarten/verjaardag-man/grappig-m/hallmark/een-jaguar-voor-je-verjaardag-3346861.aspx']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.ID, "btnShowSizepicker"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Standaard']"))).click()

I'm trying to click the button 'Binnenkant ' (note the trailing space). For this, I've tried:

elem = driver.find_element_by_class_name('primaryButton').click()

elem = driver.find_element_by_xpath('//button[.="Binnenkant "]').click()

elem = driver.find_element_by_xpath(//*[@id="CardSelectBar"]/div[3]/button[2]/text()).click() #xpath copied from Chrome

But I get a 'no such element' error each time.

1 Answer 1

2

There are 2 classes on this particular page: showDesktop and hideDesktop. Both include the button you search for. Try this Xpath:

"//div[contains(@class, 'showDesktop')]//button[contains(text(),'Binnenkant')]"
Sign up to request clarification or add additional context in comments.

1 Comment

That did the trick, thank you! I guess a 'duplicate name' error would be helpful for debugging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.