Clicking on Text using Selenium

Question:

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."

Asked By: MausHausi

||

Answers:

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
Answered By: Dmitriy Neledva
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.