Selenium in Python: ElementNotInteractableException: Message: element not interactable - python

I know there are lots of posts about this exception, and I've read lots of them and tried their suggestions but they don't seem to work. Maybe you guys can see what I'm doing wrong.
I'm trying to scrape this page: https://www.kichink.com/stores/barshop
Specifically the information inside the little popup that apppears when clicking the "i" button next to the green "SEGUIR" button.
The HTML for that button is this:
<button id="about" class="btn btn-default btn-info-store" data-toggle="popover" data-original-title="" title=""></button>
I've tried many things to click it, but I just keep getting the element not interactable exception.
My last attempt was with:
element_boton = wd.find_element_by_class_name("btn.btn-default.btn-info-store")
element_boton.click()
The button seems to be correctly found, but I just can't click it.
Any suggestions?

Well, I have no idea why (so maybe someone can shed some light) but after using the full xpath (for some reason not even the relative xpath worked, it had to be the full one) to search for the button, it just started working, and i was able to click it.
element_boton = wd.find_element_by_xpath('/html/body/div[1]/div[3]/div/header/div/nav[2]/div/div['
'2]/div/ul[2]/li[1]/button')

Related

Python Selenium - Cannot find element on page

I've perused SO for quite a while and cannot find the exact or similar solution to my current problem. This is my first post on SO, so I apologize if my formatting is off.
The Problem -
I'm trying to find a button on a webpage to punch me into a timeclock automatically. I am able to sign in and navigate to the correct page (it seems the page is dynamically loaded, as switching from different tabs like "Time Management" or "Pay Period" do not change the URL).
Attempts to solve -
I've tried using direct and indirect XPaths, CSS Selectors, IDs, Classes, Names, and all have failed. Included below are the different code attempts to find the button, and also a snippet of code including the button.
Button - HTML
Full Page HTML Source Code
<td>
<a onclick="return OnEmpPunchClick2(this);" id="btnEMPPUNCH_PUNCH" class="timesheet button icon " href="javascript:__doPostBack('btnEMPPUNCH_PUNCH','')">
<span> Punch</span></a>
<input type="hidden" name="hdfEMPPUNCH_PUNCH" id="hdfEMPPUNCH_PUNCH" value="0">
</td>
Attempts - PYTHON - ALL FAIL TO FIND
#All these return: "Unable to locate element"
self.browser.find_element_by_id("btnEMPPUNCH_PUNCH")
self.browser.find_element_by_xpath("//a[#id='btnEMPPUNCH_PUNCH']")
self.browser.find_element_by_css_selector('#btnEMPPUNCH_PUNCH')
#I attempted a manual wait:
wait=WebDriverWait(self.browser,30)
button = wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'#btnEMPPUNCH_PUNCH')))
#And even manually triggering the script:
self.browser.execute_script("javascript:__doPostBack('btnEMPPUNCH_PUNCH','')")
self.browser.execute_script("__doPostBack('btnEMPPUNCH_PUNCH','')")
#Returns Message: ReferenceError: __doPostBack is not defined
None of these work, and I cannot seem to figure out why that is. Any help will be greatly appreciated!

Selenium python says textarea is not interactable

I am trying to simply insert text into a textarea on a page, nothing I have tried or found on the internet has worked. When I try to either click the element or send keys to it I get an error saying that the element is not interactable, a wait doesn't solve this since if I make an explicit wait to wait until it becomes interactable it just times out every time, meaning it never becomes interactable.
This is the html of the textarea I am trying to target:
<textarea _ngcontent-kjr-c428="" placeholder="Enter Description" name="description" maxlength="120" required="" class="input-text ng-pristine ng-invalid ng-touched"></textarea>
I did also try sending text in there with javascript, but didn't manage to succeed, simply nothing happened.
Any help is appreciated since I am truly and utterly stuck
my code:
descriptionInput = wait.until(presence((By.NAME, 'description')))
descriptionInput.click()
descriptionInput.send_keys("Test")
The issue was, as #JaSON pointed out, that there were indeed more elements named description

Message: Element <input class="file-drag-target _ngcontent-tkc-69" type="file"> is not reachable by keyboard

Hey guys looking for a bit of guidance on this. I am trying to use a selenium request to upload a file using selenium. I have tested in the console whether the element is available and is clickable through selenium. However I am trying to upload a file. I can see the element no problem and can click on it so the other answers of setting the height, making the element to visible and focusing on it that I have found on stack are not relevant here nut I tried it anyway and I still get the same error.
elem = browser.find_element(By.CSS_SELECTOR, "input[type=file]")
js = "arguments[0].style.height='auto';
arguments[0].style.visibility='visible' arguments[0].focus();"
browser.execute_script(js, elem)
I have also tried moving to the element
action.move_to_element(elem)
The error is telling me the element is not reachable by keyboard. I have also tried setting the focus to the element and no luck. Wondering could someone provide some guidance on this? Thanks very much
upload = browser.find_element_by_css_selector("input[type=file]")
upload.send_keys("/test/")

Attempting to click a button in Python using Selenium WebDriver (Firefox)

I am attempting to click a button on a html page using Python and selenium web driver.
This is the source code of the page http://pastebin.com/112g1Gje.
I believe the relevant portion is at the end. I'm trying to click the button that says "Message"
Normally I would do something like:
driver.find_element_by_id("message-modal").click()
However that doesn't work.
I have tried:
driver.find_element_by_id("message_label").click()
driver.execute_script('document.getElementByName(" Message ").click();')
driver.execute_script('document.getElementById("message-senderId").click();')
driver.execute_script('document.getElementById("message- label").addEventListener("submit", function())')
...etc.
All of them don't work.
For the stars by the way I had the same issue. It was hard to click it, but I figured this part out. This worked:
driver.execute_script('document.getElementById("star_41094_4").checked = true;')
I think this page is switching up the numbers for the star. So that number may not work right now. But that's a separate issue. Does anybody know?
EDIT: I have asked a moderator to delete this thread. I had a number of things wrong here. I am creating a new one.
Try
driver.find_element_by_xpath("//*[text()='Open Message Modal']").click()
Happy Coding :)
I think you forgot to code a button that opens that message-modal. Better create that button first like.
<button class="btn" id="btn-message-modal" data-toggle="modal" data-target="#message-modal"> Open Message Modal</btn>\
Then try this:
driver.find_element_by_id("btn-message-modal").click()
PS
message-modal is the id of the modal container that is why nothing happens
On this code
driver.find_element_by_id("message-modal").click()
driver.find_element_by_classname("btn").click() works

Handling Modal Dialogs with Selenium in Python

I am using Selenium to automate a process and the page I want to interact to opens a modal dialog every time someone access it. I want to be able to interact with the main page properly, so I need a way to close the dialog. However, I've tried some suggestions on handling modal dialogs and they are not working as they should. There are two buttons I can click on to close the dialog, one of them is:
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Fechar</button>
</div>
I've tried to locate this button and then click on it with:
test = driver.find_element_by_link_text("Fechar")
test.click()
But this is not closing the dialog. Using:
test = driver.find_element_by_link_text("Fechar")
test.send_keys(Keys.RETURN)
gives me the following error:
no such element: Unable to locate element: {"method":"link text","selector":"Fechar"}.
I've also thought of writing a script to navigate through the dialog using the TAB key and then hitting Enter when the close button is reached. But I don't know if this the proper way to handle the problem and if this can be done without issues. Thanks in advance.
With find_element_by_link_text method, you won't find a button, you will find a link element (a). Reference.
If you want to get that button, you could use:
driver.find_element_by_css_selector('.modal-footer > button[data-dismiss="modal"]')

Categories