I'm trying to click on a radio button on a web page which is dynamic. I tried classname, xpath and nothing works.
The code that contains the radio button is :
<input id="radiofield-1247-inputEl" class="x-form-field x-form-radio x-form-cb" type="button" hidefocus="true" autocomplete="off" role="radio">
There is a label which is adjacent to the button.
<label id="radiofield-1247-boxLabelEl" class="x-form-cb-label x-form-cb-label-after" for="radiofield-1247-inputEl">Yes</label>
I tried :
driver.find_element_by_xpath("//*[#type='radio'][#class='#class here'") #.click() and this doesn't work.
I tried passing the absolute xpath, which also fails. There is no name or id to do a search for.
You're trying type="radio" while on provided HTML it's type="button"...
Try following XPath:
driver.find_element_by_xpath('//input[contains(#id, "radiofield-")][#role="radio"]')
Related
#This issue was resolved becouse it was an iframe issue, that's why the element couldn't be found, the code I used to make it work is:
button = driver.find_elements_by_css_selector(".btn.btn-primary")
I have the following html code:
<td>
<input type="hidden" value="xxxxx" id="1_nombre_77074118_1">
<input type="hidden" value="xxx#xxx.cl" id="1_email_77074118_1">
<a class="btn btn-primary" href="" onclick="javascript:submitEntrar(true,1,77074118,'1');return false;">Ingresar como usuario</a>
</td>
I need to click the class="btn btn-primary / Ingresar como usuario" button, but can't seem to find the element?
This is my code:
button = driver.find_elements_by_class_name("btn btn-primary")
print(len(button))
for b in button:
print(button)
(Both print's don't return element's becouse they where not found).
I also tried by XPATH but it didin't work, this is the XPATH:
//*[#id="container"]/section/div[1]/table/tbody/tr[1]/td[3]/a
Full XPATH:
/html/body/div[1]/div[1]/section/div[1]/table/tbody/tr[1]/td[3]/a
Thanks a lot!
First of all since there are multiple class names in the element instead of
button = driver.find_elements_by_class_name("btn btn-primary")
Try
button = driver.find_elements_by_css_selector(".btn.btn-primary")
Also you possibly have to add delay / wait before accessing these elements.
Try
button = driver.find_elements_by_css_selector(".btn.btn-primary)
can you try this as we can search and click on the element based on the text
driver.find_element_by_xpath("//a[text()='Ingresar como usuario']")
driver.find_element_by_xpath("//*[contains(text()='Ingresar como usuario')]")
driver.find_element_by_partial_link_text("Ingresar como usuario")
Also, recommend using explicitWait
button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Ingresar como usuario']")))
button.click()
It is because of two reasons
Class call should prepend with . Eg) .btn
You are trying to call with two classes. If you notice btn and btn-primary are two different classes, so you could call using either
button = driver.find_elements_by_css_selector(".btn.btn-primary")
Or
button = driver.find_elements_by_class_name(".btn.btn-primary")
Im trying to locate and click an element (checkbox) from a big selection of checkboxes on a html site using python and selenium webdriver. HTML code looks like this:
HTML Code
<div class="checkbox-inline col-md-5 col-lg-3 col-sm-6 m-l-sm rightCheckBox">
<input type="checkbox" checked="checked" class="i-checks" name="PanelsContainer:tabsContentView:5:listTabs:rights-group-container:right-type-view:2:right-view:2:affected-right" disabled="disabled" id="id199"> <label>Delete group</label>
</div>
My problem is that the only unique identifier is:
<label>Delete group</label>
All other elements/id's/names are used by other checkboxes or changes from page to page.
I have tried the following code:
driver.find_element_by_xpath("//label[contains(text(), 'Delete group')]").click()
But I only get error when using this.
Error: element not interactable
Anyone able to help with this?
Try the below xpath
//label[contains(text(), 'Delete group')]//ancestor::div//input
Try with Javascript.
checkBox = driver.find_element_by_xpath("//label[text()='Delete group']//ancestor::div//input")
# Scroll to checkbox if its not in screen
driver.execute_script("arguments[0].scrollIntoView();", checkBox)
driver.execute_script("arguments[0].click();", checkBox)
Note : As per HTML shared by you, checkbox is in Disabled state, so i am not sure click will trigger any action. However above code will click your checkbox.
HTML:
<button aria-expanded="false" class="pv-profile-section__see-more-inline link" data-ember-action data-ember-action-2611="2611">
Python:
buttons = browser.find_elements_by_xpath(u'//button[#class="pv-profile-section__see-more-inline link"]')
print(buttons)
for degree in buttons:
degree.click()
there are two button with the same tag written above but it does not access any of them. It just print the empty list.
I have used the below code to click the element.But it failed to locate the element and shows element not visible.
elem3=driver.find_element_by_xpath(".//*[#id='check-box']")
elem3.click()
The html code:
<span id="Some-span" class="urCWhl" title="Indicator">
<input id="check-box" class="urC" type="checkbox" hidefocus="hidefocus" ti="-1" tabindex="-1" ct="C"/>
<span id="label-lbl" class="name_class" style="width:100%;box-sizing:border-box;" unselectable="on" f="some-id" ti="0" tabindex="0" title="Indicator"></span>
You can try something like this:
element = driver.find_element_by_xpath(".//*[#id='check-box']")
driver.execute_script("arguments[0].click();", element)
The input might be inside a frame? If so switch to that frame by doing:
driver.switch_to_frame('framename')
or if not, try to find via id then click the element:
driver.find_element_by_id('check-box').click()
one thing to remember is that if the checkbox is already have a value, if you click the checkbox, the check will be removed. if you want to have the checkbox to have a true value always, you may do this:
driver.execute_script("document.getElementById('check-box').setAttribute('checked','');")
This will execute a javascript to always have a true value on the checkbox
I would like to click on button "query"
my inspect element gives the following code for the button query and exit.
<TD class=font9 colSpan=4 align=center> int pageSize <INPUT class=bg0 size=3 value=10 name=pageSize> Article <!-- <input type="button" class="imagesButton" name="btnPrint" value="打 印" onclick="doPrint(gFormName);">--> <INPUT onclick=doFind(gFormName); class=imagesButton type=button value=query name=Submit> <!-- <input type="button" class="imagesButton4" name="Submit2" value="yesQuery">
--><INPUT onclick=doExit() class=imagesButton type=button value=exit name=Submit5> </TD>
I tried the below code for the click
import mechanize
br = mechanize.Browser()
submit_response = br.submit(name='Submit',label= 'query')
while executing the code I faced an error
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 3185, in _find_control
raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'Submit', kind 'clickable', label 'query'
can any on help me how to click on button
the buttons trigger javascript functions ("doPrint(gFormName)",...)
on http://bytes.com/topic/python/answers/764326-using-mechanize-python-navigate-website is a similar problem. it was solved by triggering the javascript action of the button manually
br.form.action="button_action"
see also http://www.stackoverflow.com/questions/1806238/mechanize-python-click-a-button