0

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)
3
  • how many element does it identify with xpath //div//label[contains(., 'Select all')] Commented Sep 6, 2022 at 23:50
  • @SonaliDas - I have not counted the number of elements. I should have been more specific with the other attempts that I tried. For example, there is an ID associated with the label I am trying to select so I first tried driver.find_element(By.ID,'availableAll').click(). The behavior is the same with the XPATH code. Commented Sep 7, 2022 at 13:52
  • @toyotaSupra - There is not actually any errors in this case. The code I thought would work is driver.find_element(By.ID,'availableAll').click(). The div that contains the label shifts a little when the code is executed, but it is not selected and there is no error. I will take your advice on posting the code next time. Thank you. Commented Sep 7, 2022 at 13:55

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your reply. I tried that initially and it did not work. I just tried again to make sure I didn't do something wrong the first time. What is strange is that the entire div shifts position a bit when that code is executed. I have tried several other options that affect the div in the same way but the 'Select all' is never selected.

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.