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()
Related
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
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
I don't have experience in Selenium. I have tried a couple of things to click a submit button inside a form but nothing is working for me. Please help me out to solve this problem.
I found that the button is enabled (is_enabled()), but not displayed (is_displayed()).
I tried the following options one by one. I have added the consecutive result of that code in the comment.
z=driver.find_element_by_xpath("//input[#name='commit']")
z.click() #It is showing error, Message: element not interactable
z.send_keys(Keys.ENTER) #It is showing error, Message: element not interactable
driver.execute_script("arguments[0].click();", z) #Shows no error, but nothing happens
z.submit() #Shows no error, but nothing happens
I tried with driver.implicitly_wait(20) but no luck.
I tried with until option too but it gives error.
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='commit']"))).submit() #This raises TimeoutException
The HTML code is following
input type="submit" name="commit" value="Calculate" class="btn btn-primary" autocomplete="off" data-disable-with="Calculate"
The webpage link is : https://proteins.plus/ktypdbdd9c38b7-1738-45fd-a0fb-90ea86f5dd8b
I clicked on "DoGSiteScorer Binding site detection", then "DoGSiteScorer" button. Now I want to lick the "Calculate" button which is not working.
How should I do it then?
The problem is this:
z=driver.find_element_by_xpath("//input[#name='commit']")
returns 11 elements on that page, and you can't call click() on 11 elements.
Assuming you want to click the red Calculate button, try this:
z = driver.find_element_by_xpath("(//input[#name='commit'])[2]")
z.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()