-2

New to python here. I am trying to have my script click a checkbox with a given input value. Unfortunately there is no input ID. Using find_element returns with error:

Unable to locate element

Using find_elements() returns a list and therefore I get the error:

'list' object has no attribute 'click'

This is the code I have had trouble with.

OldJob = driver.find_elements_by_xpath("//input[@value='0   ']")
OldJob.click()

Here is the html:

Here is the html.

Any thoughts on how I can get around this?

Guy
  • 46,488
  • 10
  • 44
  • 88
Raj
  • 1
  • 3
    Please read [mcve] and edit your post accordingly. Adding picture of code is not good practice no one will write that for you by looking at the image – Dev Mar 05 '20 at 14:34
  • 3
    You already solved your own problem: You need to iterate the list to find the correct element or you need to use `find_element_by_xpath` with a selector that matches only the wanted element. Without the full html we can not tell if you are using the correct selector. – Frieder Mar 05 '20 at 14:45
  • The element has a name... have you tried `driver.find_element_by_css_selector("input[name='RowNum']")` or `driver.find_element_by_name("RowNum")`? – JeffC Mar 05 '20 at 19:57

1 Answers1

0

To locate the <input> element you can use either of the following Locator Strategies as follows:

  • cssSelector:

    driver.find_element_by_css_selector("input[name='RowNum'][value^='0'][type='checkbox']")
    
  • xpath:

    driver.find_element_by_xpath("//input[@name='RowNum' and contains(@value, '0')][@type='checkbox']")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352