When I executing the test case in console an error is displayed ->
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I add the location of the file but script be broken
My code
driver.find_element(By.XPATH, '/html/body/div[1]/section/section/main/div/div/div/div/form/div[4]').send_keys('E:\Descargas\Support-GPSD-945.zip')
Any solution?
CodePudding user response:
As the error message says, the element you're locating isn't interactable. That means that Selenium is looking at the element and has decided it's not something that can be clicked, typed into, etc.
This usually happens for one of two reasons:
- The page/element hasn't finished loading or the DOM is in flux
- The element truely isn't interactable
I think you're having problem two, but just in case, I'm going to leave suggestions for both.
If the Element hasn't finished loading
If the problem is the first case, you should add a wait to ensure the page is fully loaded and the DOM has settled down. Best practise is usually to add a wait for the appearance of an element that ensures the page has loaded, rather then waiting a static amount of seconds...
But a static wait is OK while debugging, IMO.
If the element truely isn't interactable
It looks like you're selecting a div
, not an input. That is, you're trying to send text to part of the page structure, rather then the form element itself. I'm guessing you've generated this XPath using a tool?
The best solution here is to adjust your selector so it points to the form element. If the element has a unique ID or class name, use a CSS selector with that. (If it doesn't, tell your development team off for not writing the front end in a more testable way).
If the element doesn't have an ID or class name, you'll need to edit your XPath to select the input, rather then the div. Without seeing your code I can only guess, but adding:
/input
to the end of the selector might do it.