"Element click intercepted" Error while trying to click on CheckBox - python

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()

Related

Can't Click Radio Button in Selenium Using Python

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

Python Selenium - Error: Element not Interactable. Interactive with website pop up window

I'm running a web scraper on my company's website so I can create elements every month. In testing, I have everything working until I get to interact with a pop up menu.
Code that interacts with pop up:
driver.get("www.website.com")
driver.find_element(By.ID, "ButtonCreatePeriod").click()
time.sleep(1)
driver.find_element(By.ID, "NoExpiration").click()
time.sleep(1)
driver.find_element_by_css_selector('[class="k-widget k-dropdown shorterDropDown"]').click()
time.sleep(3)
ddelement2 = driver.find_element_by_xpath("//*[text()='December 2021']")
action2 = ActionChains(driver)
action2.click(on_element=ddelement2).perform()
On action2.click(on_element=ddelement2).perform() I am getting the error:
"Message: element not interactable: [object HTMLLIElement] has no size and location"
I'm guessing this has to do with interacting with the popup.
Within the pop up that is opened with I click "ButtonCreatePeriod" I am opening the drop down menu defined as class="k-widget k-dropdown shorterDropDown".Within this drop down, I need to select the option with the text "December 2021". I cannot use IDs or numerical values here since this varies across other UIs in the website. The options shown on the dropdown are scrollable which could be an issue too.
I used this same code on another UI on the website with no issues but that one did not present a pop up, although it was scrollable.
Any ideas as to how I could have it select "December 2021" here?
Error generated per #cruisepandey suggestion:
Message: element click intercepted: Element <span title="" class="k widget
k-dropdown shorterDropDown k-state-disabled ic-dropdown-readonly"
unselectable="on" role="listbox" aria-haspopup="listbox" aria-
expanded="false" tabindex="0" aria-
owns="MfrCoreTermEffectivePeriodKey_listbox" aria-live="polite" aria-
disabled="false" aria-readonly="true" aria-busy="false" aria-
activedescendant="l581310d-64f8-4bbc-9354-71b6f041d0e3" style="">...
</span> is not clickable at point (434, 383). Other element would
receive the click: <p>...</p>
(Session info: chrome=93.0.4577.82)`
Solution
I basically had to dig deeper into the HTML code and use xpath to further define the lists within the drop down.
driver.find_element_by_css_selector('[class="k-widget k-dropdown shorterDropDown"]').click()
time.sleep(1)
driver.find_element_by_xpath("//div[#id='MfrCoreTermExpirationPeriodKey-list']//li[text()='December 2021']").click()
Possible reasons could be
Screen is not maximized, if so please maximize it when you launch the URL.
driver.maximize_window()
ActionChain may help.
time.sleep(5)
ActionChains(driver).move_to_element(driver.find_element(By.CSS_SELECTOR, ".k-widget.k-dropdown.shorterDropDown")).click().perform()
JS intervention with scrollInto view may help.
time.sleep(5)
ele = driver.find_element(By.CSS_SELECTOR, ".k-widget.k-dropdown.shorterDropDown")
driver.execute_script("arguments[0].scrollIntoView(true);", ele)
Imports :
from selenium.webdriver.common.action_chains import ActionChains

Element not being clicked even though it is found using Selenium

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']"))))

Can't Click Element

I am trying to make click for this element,
but getting error like
>> ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (271, 705)
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#action="/battle/"]/div/input[2]')))
element.click();
This is not helping also getting timeoutexception. I think element kinda covered
with:
[driver.find_element_by_xpath('//[#action="/battle/"]/div/input[2]').click()]
<form action="/battle/" method="post" name="4416" id="4416" onsubmit="get('/battle/', '', this); disableSubmitButton(this); return false;"><div class="battleView" style="float:left; width:65%;"><h3 class="heading-maroon no-right-border-rad margin-right-2">Attack Results</h3><table cellpadding="0" cellspacing="0" style="width: 80%; text-align: center; margin: 0 auto;">
...
</tbody></table><input type="hidden" class="button-maroon button-small" name="action" value="attack">
<input type="submit" class="button-maroon button-small" value=" Attack .. "></div>
</form>
It looks like it's showing the X/Y coordinates (271,705) in the error message. I'd try a macro product like AppRobotic to look up the X/Y coordinates of elements that you have issues finding with XPATH, moving the mouse, or sending keystroke TABS, and clicking it. A simple example:
import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
# navigate to Yahoo
driver = webdriver.Firefox()
driver.get('https://www.yahoo.com')
# sleep 1 second
x.Wait(1000)
link = driver.find_element_by_link_text('Mail')
if len(link) > 0
link[0].click()
else
x.Wait(3000)
# use UI Item Explorer to get X,Y coordinates of Mail box
x.MoveCursor(271,705)
# click inside Search box
x.MouseLeftClick
# could also try tabbing over and pressing Enter
x.Type("{TAB}")
x.Type("{ENTER}")
Another idea is to try scrolling to the element with Selenium first:
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_xpath('//[#action="/battle/"]/div/input[2]')
actionchains = ActionChains(driver)
actionchains.move_to_element(element).perform()

Python - Unable to click button in Selenium under tooltip, webpage throws request error

This is the element I am trying to click (the info button). It's located on pokemongomap.info, and you can see it in chrome devtools under any pokestop or gym.
<a href="#" target="_self" class="tooltip tooltipstered" id="infoboxmoreinfobtnbind" style="display: inline;">
<div id="infoboxmoreinfohit"></div>
<div id="infoboxmoreinfobtn" class="infoboxbtn">
<i class="fa fa-info-circle" aria-hidden="true" style="color: rgb(57, 135, 140);">
</i>
</div>
</a>
I am unable to click it using ActionChains, element.click(), or anything else. If I try to click it using either of those methods, I get a request error from the website. Can anyone help me? Here is some of the code I have tried.
wait = WebDriverWait(driver, 10)
actions = Actions(driver)
element = wait.until(EC.element_to_be_clickable((By.ID, 'infoboxmoreinfobtnbind')))
#element = wait.until(EC.element_to_be_clickable((By.XPATH, '//i[#class="fa fa-info-circle"]'))) also throws error when clicked
#actions.move_to_element(element).click(element).perform() doesn't work either.
action = actions.move_to_element(element)
action.click()
action.perform()
I've also tried clicking on other infobox elements using ActionChains or element.click(), all of them either do nothing or give a request error or aren't clickable at the point.
As a last resort, you can use JS with execute_script:
wait = WebDriverWait(driver, 10)
actions = Actions(driver)
element = wait.until(EC.element_to_be_clickable((By.ID, 'infoboxmoreinfobtnbind')))
driver.execute_script("$(arguments[0]).click();", element)
This is not a humanlike automation but it should do the job...
Hope this helps you!

Categories

Resources