Here is the HTML Code:
<div class="ui-helper-hidden-accessible">
<input type="radio" name="group2" value="yes">
</div>
Full script
Here are the code which i've tried to click the radio button:
driver.find_element(By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]').click()
AND
rdbutton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]'))).click()
AND
rdbutton = driver.find_elements(By.XPATH, "//input[#name='group2']")
for rdbuttons in rdbutton:
if rdbuttons.is_selected():
pass
else:
rdbuttons.click()
It seems that you are using wrong locator. From the HTML you have given i think you are trying to click on radio button that have label Ya if this is the case then try with below xpath:
"//label[contains(text(),'Ya')]"
OR
"//*[normalize-space()='Ya']"
If this does not solve your problem, so please explain and add HTML of proper element either by screenshot or in textual format
Related
I'm a real noob and I started to learn Python a few weeks ago.
I need to create an automation for eCommerce, I need to log in, select a page, **select a checkbox ** and click the button "submit". It seems very simple I know but on this website, the normal procedure doesn't work:
This is the HTML code:
<div class="loader-container"\>
<table class="table-grey table__orders table"\>
<thead\>
<th class="check-all table__orders-checker"\>
*\*\<div class="check-all__box"\>
<input type="checkbox" value="checkAll"\>\*\*
</div\>
This is what I coded to click the "check all" checkbox:
driver.find_element(
By.xpath, "//div[contains(#class, 'loader-container')]/table/thead/tr/th/div/input[#type='checkbox']").click()
I've tried also:
WebDriverWait(driver, 30).until(EC.element_to_be_clickable(
By.XPATH, "//div[contains(#class, 'loader-container')]/table/thead/tr/th/div/input[#type='checkbox']")).click()
Both without success, nothing happens when it should click this checkbox, I've also other try looking on this forum or YouTube but I'm missing something because I can't fix it.
Thank you in advance for your patience!
I am working with the following website: www.offerte.smartpaws.ch
I am trying to use the French site: www.offerte.smartpaws.ch/fr
I have a piece of code that works with the German part but for some reason I get an error when trying to do the same thing on the French side, even if the elements are identical.
I have the following code to select the year:
for year in range(21,12,-1):
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[#id="id_form-0-dob"]'))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[#id="id_form-0-dob_root"]/div/div/div/div/div[1]/select[1]'))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//select[#class="picker__select--year" and #aria-controls="id_form-0-dob_table"]//option[text()='+str(2000 + year) +']'))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="id_form-0-dob_root"]/div/div/div/div/div[2]/button'))).click()
This code is supposed to go through a range of years, click on the calendar option, then click on the dropdown for years and take the selected year, finally, we close the calendar.
This method is working fine in the German side, but fails at the French side, with the following error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="text" name="form-0-dob" id="id_form-0-dob" readonly="" class="picker__input" aria-haspopup="true" aria-expanded="false" aria-readonly="false" aria-owns="id_form-0-dob_root"> is not clickable at point (921, 572). Other element would receive the click: <label for="id_form-0-dob">...</label>
Thank you for any advice or sugestions.
Try clicking the parent div element of the input. Seems to work for me for both language sites:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[#id="id_form-0-dob"]/..'))).click()
I'm trying to click on an element (radio button) using Selenium (in Python), I can't disclose the URL because it's a private corporate intranet, but will share the relevants part of code.
So basically this element is within an iframe, thus, I've used the following code to get the element:
# Select the item on main DOM that will udpate the iframe contents
wait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[#id='sm20']"))).click()
# Don't sleep, but only WedDriverWait...
wait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[#name='ifrInterior']")))
# Select the element inside the iframe and click
wait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='gestionesPropias_Equipo']"))).click()
The HTML code for the element is this:
<span class="W1">
<input type="radio" name="gestionesPropias_Equipo" value="1" onclick="javascript:indicadorPropiasEquipo(); ocultarPaginacion('1'); limpiarDatosCapaResultado();">
</span>
I'm interested in clicking this because when we click on it a drop-down is enabled:
If clicked then the dropdown is enabled:
The intersting HTML code for this is
<span id="filtroAsignado" class="W30">
<select name="nuumaAsignado" class="W84">
<option value="">[Todo mi equipo]</option></select>
</span>
Debugging a bit Selenium I can see that the elemtn is found:
And this is actually the base64 image of the element, which is the expected radio button
So I'm wondering why the element actually does not get clicked??
UPDATE: Based on request from #DebanjanB, I'm adding the HTML code from the iframe, which is enclosed inside a div in the main page:
<div id="contenido">
<iframe frameborder="0" id="ifrInterior" name="ifrInterior" src="Seguimiento.do?metodo=inicio" scrolling="auto" frameborder="0"></iframe>
</div>
Actually if I look for the word "iframe", there's only one...
Now checking the iframe source itself, has several iframes hidden but the element I need to interact with is in the iframe mentioned above, the only thing that I forgot to mention is that it's inside a form, but I guess that's not relevant? You can see the whole structure in the following image:
Great question. If you know that selenium found the element, you can use Javascript to click the element directly.
The syntax is:
driver.execute_script("arguments[0].click();", element)
You can also do this, which works the same way:
automate.execute_script("arguments[0].click();", wait.until(EC.element_to_be_clickable((By.XPATH, 'Your xpath here'))))
Essentially you are having Selenium run a javascript click on the element you have found which bypasses Selenium. Let me know if this helps!
I don't see any such issue with your code block either. Perhaps you can try out either of the following options:
Using ActionChains:
ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='gestionesPropias_Equipo' and #type='radio']")))).click().perform()
Using executeScript() method:
driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='gestionesPropias_Equipo' and #type='radio']"))))
I want to click on a check box after I load up a page, but I get the error message below:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <img class="checkboximage" src="/images/nav/ns_x.gif" alt=""> is not clickable at point (843, 7). Other element would receive the click: <a class="ns-help" onclick="nlPopupHelp('EDIT_TRAN_CUSTINVC');" tabindex="0" onkeypress="(event.keyCode == 13 || event.charCode == 32) && nlPopupHelp('EDIT_TRAN_CUSTINVC');">...</a>
This is what I have right now: I've tried several other methods before this
collectionsbox = driver.find_element(By.CSS_SELECTOR,"#custbody_in_collections_fs_inp")
driver.execute_script("arguments[0].scrollIntoView(true)", collectionsbox)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[#id='custbody_in_collections_fs']//img[#class='checkboximage']"))).click()
collectionsbox.click() #USUALLY FAILS RIGHT HERE
savebutton = driver.find_element(By.XPATH,"//input[#id='btn_multibutton_submitter']")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#id='btn_multibutton_submitter']"))).click()
driver.execute_script("arguments[0].scrollIntoView(true)", savebutton)
savebutton.click()
time.sleep(2)
driver.switch_to.alert.accept()
I've tried the EC method, waited several seconds, scroll down to view the element. I've even used Xpath, ID, and CSS.
<input onclick="setEventCancelBubble(event); this.isvalid=(nlapiValidateField(null,'custbody_in_collections')); if (this.isvalid) {setWindowChanged(window, true);nlapiFieldChanged(null,'custbody_in_collections');;} else if ( window.loadcomplete && !document.page_is_resetting ) {setFormValue(this, !this.checked);}" aria-labelledby="custbody_in_collections_fs_lbl" onchange="NLCheckboxOnChange(this); " onkeypress="NLCheckboxOnKeyPress(event); return true;" name="custbody_in_collections" id="custbody_in_collections_fs_inp" type="checkbox" value="T" class="checkbox" style="">
<input type="hidden" name="custbody_in_collections_send" style="">
<img class="checkboximage" src="/images/nav/ns_x.gif" alt="" style="">
All I need is click the checkbox and click save up top.
Seems like another element on the DOM is unintentionally hiding the element you are trying to click. You can try executing Javascript for the click instead. This usually resolves the issue for me.
Instead of collectionsbox.click() #USUALLY FAILS RIGHT HERE, you can replace with:
driver.execute_script("arguments[0].click();", collectionsbox)
To address element is not clickable at point (x, y) error. We can follow below approaches to resolve this issue
Solution
1. Action Class
WebElement element = driver.findElement(By.id("yourelement ID"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
2. Element not getting clicked as it is not within Viewport
use JavascriptExecutor to get element within the Viewport:
checkBox=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"yourelement Xpath")))
ActionChains(driver).move_to_element(checkBox).click(checkBox).perform()
I cannot create the .click()-action on the button.
HTML:
<button class="btn__type btn__type_close">Закрыть</button>
I try to make an element clickable for execute_script:
driver.execute_script("return document.getElementsByClassName('.btn__type_close')").click()
My code using Selenium:
driver.find_element_by_css_selector('button.btn__type_close').click()
None of the methods is working.
Question: How will it be correct?
Did you try clicking using XPath?
WebElement btnClose=driver.findElement(By.xpath("//button[#class='btn__type btn__type_close']"));
if(btnClose.isEnabled()){
btnClose.click();
}