bemery777
bemery777

Reputation: 9

How to click on a label tag within nested divs in Selenium Python

I am trying to click on an 'Select all' label on a website but I am having troubles. The HTML has it the label nested within several divs. HTML Example here.

I have tried various XPATH examples but nothing actually clicks the element. Any ideas?

Here is my latest attempt:

driver.find_element(By.XPATH,"//div//label[contains(., 'Select all')]")strong text

UPDATE

I was able to select the options individually with the following code:

select_element = driver.find_element(By.ID,'availableList')
select_object = Select(select_element)


all_available_options = select_object.options
count_of_options = len(all_available_options)
for x in range(count_of_options):
    select_object.select_by_index(x)

Upvotes: 0

Views: 94

Answers (1)

codewithme
codewithme

Reputation: 1

It has unique ID you can use that instead of XPATH.

driver.find_element(By.ID,'availableAll').click()

or you can use full XPATH it will work.

Upvotes: 0

Related Questions