Using Selenium in Python3 to select a radio button image here. And below is the code I'm using to select the radio button but it doesn't work.
emailElem = browser.find_element_by_class_name('SSR_DUMMY_RECV1$sels$0')
emailElem.click()
Using Selenium in Python3 to select a radio button image here. And below is the code I'm using to select the radio button but it doesn't work.
emailElem = browser.find_element_by_class_name('SSR_DUMMY_RECV1$sels$0')
emailElem.click()
"by class name" locator should be used to locate elements by class attribute values, in this case use "by id" or "by name" instead:
emailElem = browser.find_element_by_id('SSR_DUMMY_RECV1$sels$0')
emailElem = browser.find_element_by_name('SSR_DUMMY_RECV1$sels$0')
Just add a bit more to alecxe's answer.
You need to be sure that its id
and name
are unique.
If they are not unique, you can add more attributes to find by
methods, e.g.
emailElem = browser.find_element_by_css_selector("input[id='SSR_DUMMY_RECV1$sels$0'][class=''PSRADIOBUTTON][type='radio']")
The more attributes you use, the more likely you will locate a unique element.
Based on comments to the original question, you claim you're getting this error:
Traceback (most recent call last):
File "./fsu.py", line 20, in <module>
emailElem.click()
AttributeError: 'list' object has no attribute 'click'
That sounds like you're calling one of the get_elements_*
functions rather than get_element_*
(note the plural elements
).
Error messages carry a lot of information in them, and need to be taken literally. Your error message is telling you that a list doesn't have a click method, which is true. Reading between the lines it means that the object on which you're calling .click()
is a list, even though you think it is an element.