0

I want to click on this checkbox:

enter image description here

<label for="auth:RegistrationForm:multistep[gtcAgbChechbox]" class="checkbox">
    ::before
    Ich bestätige, dass ich die
    <a href="/gtc" title="AGB" class="popup" data-title="gtc" data-funnelize="A::Click,O::###page###,T::Link,ST::GTC">AGB</a>
    gelesen und akzeptiert habe.
</label>

But I can't click on the checkbox itself because the label has everything in it. I tried to do so but then it sometimes clicks on the link AGB which I don't want to.

enter image description here

So I tried clicking on "Ich bestätige, dass ich die" with:

WebDriverWait(driver, 15).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="auth:RegistrationForm:multistep[signupForm]"]/div[4]/div[2]/div[1]/label/text()[1]'))).click()

But then I get the error "The result of the xpath is [object Text]. It should be an element."

2
  • Can you post the URL? Commented Nov 4, 2022 at 7:55
  • Post the exact URL in which that checkbox is available. Commented Nov 4, 2022 at 7:58

1 Answer 1

1

there you can locate 4 things

<label for="auth:RegistrationForm:multistep[gtcAgbChechbox]" class="checkbox">

Ich bestätige, dass ich die 

<a href="/gtc" title="AGB" class="popup" data-title="gtc" data-funnelize="A::Click,O::###page###,T::Link,ST::GTC">AGB</a> 

gelesen und akzeptiert habe.</label>

you need to locate the first one = 'label' only without touching the other 3 that left

look at this code

driver = webdriver.Firefox()
driver.implicitly_wait(10)

driver.get('https://www.fremdgehen69.com/')

driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[2]/form/div[1]/div/div[3]/div').click()

driver.find_element(By.XPATH, '//*[@id="auth:RegistrationForm:multistep[msReg_username]"]').send_keys('anything')
driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[2]/form/div[2]/div/div[4]/div[2]').click()


driver.find_element(By.XPATH, '//*[@id="auth:RegistrationForm:multistep[msReg_password]"]').send_keys('anything')
driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[2]/form/div[3]/div/div[3]/div[2]').click()


#look at this only, all upper things are password inputting
driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[2]/form/div[4]/div[2]/div[1]/label').click()   #this line takes 'label' only
Sign up to request clarification or add additional context in comments.

3 Comments

Hi but when I use your last line with that XPATH sometimes Selenium clicks on AGB. I only want to klick on "Ich bestätige, dass ich die" to solve this problem...
It's strange because there should be /a at the end of xpath only then it would touch that a tag link. You can try then css_selector instead of xpath. The last line should be driver.find_element(By.CSS_SELECTOR, 'div.formStep:nth-child(2) > div:nth-child(1) > label:nth-child(2)').click()
this css_selector takes check box, and this one # div.formStep:nth-child(2) > div:nth-child(1) > label:nth-child(2) > a:nth-child(1) would take a tag, this one has additional ` > a:nth-child(1)` at the end.

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.