Python script:
userId_box =driver.find_element_by_id("userId")
userId_box.send_keys(usr)
Inspect element:
<ion-input class="passwordinput sc-ion-input-md-h sc-ion-input-md-s md hydrated" placeholder="User ID" id="userId" type="text" value=""><ion-icon class="eye md hydrated" role="img"></ion-icon><input class="native-input sc-ion-input-md" aria-labelledby="ion-input-0-lbl" autocapitalize="off" autocomplete="off" autocorrect="off" maxlength="3" name="ion-input-0" placeholder="User ID" type="text"></ion-input>
Error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
You can try explicit wait
Sometimes pausing the program also helps
Sometimes the element is not in view and you have to scroll to the element in order to interact with the element. You can also try that using JavascriptExecutor
Related
Here is form element on the page
<input class="step__input" valid="true" id="capture-first-name" data-capture-id="first-name" name="first-name" placeholder="First Name" type="text" minlength="2" autocomplete="given-name" maxlength="32" pattern="((?!(\s{2})).){2,32}" autocapitalize="on">
When I do this...
browser.find_element_by_xpath('capture-first-name').send_keys('Adam')
I get error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"capture-first-name"}
(Session info: chrome=92.0.4515.159)
How can I fix this?
That's an id.
You should use
browser.find_element_by_id('capture-first-name').send_keys('Adam')
instead of by_xpath
In case you wanna stick with xpath
browser.find_element_by_xpath("//input[#id='capture-first-name']").send_keys('Adam')
I have been struggling to locate an element in a span class. The element is a radio-checkmark button. Here is the html:
<span class="radio-container" for="searchType_2">
<input class="form-check-input" type="radio" name="searchType" id="searchType_2" value="cidade">
<span class="radio-checkmark">
::after
As the classes above are not unique, I tried the following:
dropdown_menu = self.driver.find_element_by_css_selector('[for="searchType_2"] .radio-checkmark')
When I do the inspection and search using the CSS selector above it works. It shows me as 1 of 1. But when I run the code, I get the following exception:
no such element: Unable to locate element: {"method":"css selector","selector":"[for="searchType_2"] .radio-checkmark"}
(Session info: chrome=92.0.4515.107
Thanks
The element you are trying to access is inside an iframe. You need to switch to the iframe before accessing any element inside it
driver.switch_to_frame(driver.find_element_by_xpath("//iframe[#class='cz-map-frame']"))
driver.find_element_by_xpath("//input[#id='searchType_2']//following::span[#class='radio-checkmark'][1]").click();
I'm a newbie in coding with python and selenium. I try to find an element in a web-page by its class name.
<input type="email" class="whsOnd zHQkBf" jsname="YPqjbf"
autocomplete="username" spellcheck="false" tabindex="0"
aria-label="Adresse e-mail ou numéro de téléphone" name="identifier"
value="" autocapitalize="none" id="identifierId" dir="ltr"
data-initial-dir="ltr" data-initial-value="">
But each time I've tried I have this error.
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".whsOnd zHQkBf"}
I don't understand why because I verified and I think that it's not in an iframe so I don't understand why do I have this message and I don't know how to manage the error.
Here are the pictures of my code and the html :
My code
The HTML of the page
Hard to tell without seeing your code and the html. Are you sure it is not in a iframe?
If not you can perhaps try to use xpath to find the element.
When inspecting the webpage in chrome you can right click the element and say copy -> copy xpath. I do recommend looking into xpath, so you know what you are searching for.
Edit:
Try using only one class name, since find_element_by_class_name() only accepts one.
This:
driver.find_element_by_class_name("zHQkBf")
instead of this:
driver.find_element_by_class_name("whsOnd zHQkBf")
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 am using selenium and python to learn about automation web testing.
I want to click on "Continue" button, while there is only span in it (I had learned that using id instead of span is so much easier)
but in this case, I want to click the span.
I am using below code:
driver.find_element_by_xpath("//span[contains(#class,'mdBtn01Txt')][contains(text(),'Continue')]").click()
here is the element :
<div class="mdLYR12Inner01">
<a class="MdBtn01 mdBtn01 ExDisabled FnSubmitBtn" style="display:none" href="#" onclick="charge(this); return false;">
<span class="mdBtn01Inner">
<span class="mdBtn01Txt">
Continue <<<(I want to click this button)
</span>
</span>
</a>
</div>
</footer>
But, I got this message below:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(#class,'mdBtn01Txt')][contains(text(),'Continue')]"}
Does not looks like a valid xpath, correct one should be
//span[#class='mdBtn01Txt']
Here is the rule to create xpath
Syntax for XPath:
XPath contains the path of the element situated at the web page. Standard syntax for creating XPath is:
Xpath=//tagname[#attribute='value']
Tagname: Tagname of the particular node.
#: Select attribute.
Attribute: Attribute name of the node.
Value: Value of the attribute.