2

I'm using Selenium and PyCharm.

Website: https://www.expedia.com/

I'm trying to click() on the Search button. I used these:

driver.find_element(By.ID, "search-button-hp-package").click()

driver.find_element_by_xpath("//*[@id='search-button-hp-package']").click()

driver.find_element_by_xpath("//button[@id='search-button-hp-package']").click()

I'm getting the following error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not intractable

Can someone explain me why the element with the id='search-button-hp-package' isn't intractable?

What I'm doing wrong?

5
  • What browser is this using? I tried Chrome in the Java version of Selenium WebDriver, and it clicked Search using the ID fine. So I think it's either a browser issue, or specific to Python.
    – anonygoose
    May 24, 2019 at 8:11
  • I'm using Chrome. Can you show me the Java code you used, please.
    – rodut
    May 24, 2019 at 8:32
  • Excluding imports and chromedriver setup and boilerplate, the code was: driver.get("expedia.com/"); driver.findElement(By.id("search-button-hp-package")).click();
    – anonygoose
    May 24, 2019 at 8:34
  • Better if you can share your code and the page source code. Have you tried to use a sleep method(not the best method) to wait until the page loads properly?
    – Syrus
    Jun 26, 2019 at 6:50
  • above solutions didn't work. any other solution?
    – user45606
    Jun 19, 2020 at 10:49

4 Answers 4

1

Looks like you are looking for the wrong element.

In the web page that loads with the link: https://www.expedia.com/ I tried to look find the element with the xpaths or even the ID mentioned by you in your description,

driver.find_element(By.ID, "search-button-hp-package").click()
driver.find_element_by_xpath("//*[@id='search-button-hp-package']").click()
driver.find_element_by_xpath("//button[@id='search-button-hp-package']").click()

This didn't return any result.

I then tried to find the element with xpath: //button[@data-testid='submit-button']

With this I was able to locate the Search button. Here is the reference HTML from browser console,

enter image description here

After I was able to locate the element I was also able to click it using Java + Selenium with this line of code:

driver.findElement(By.xpath("//button[@data-testid='submit-button']")).click();

You can use it in Python like,

driver.find_element_by_xpath("//button[@data-testid='submit-button']").click()

If I'm missing something, or it's a different element that you want to click, do let me know and I'll try to help with what I can.

0

Sometimes websites don't do what you might expect with the elements.

In this case you would expect the button element to be the thing you actually click. But instead it looks to me like the label, which is the parent element, is the element you want to click.

In short, the button is in fact not intractable. So try the some of the surrounding elements instead, parent in this case:

driver.find_element_by_xpath("//*[@id='search-button-hp-package']/..").click()

css selector alternative:

driver.find_element_by_css_selector(".package-form-fields label.search-btn-col").click()

When this happens, you can narrow down what you need to click by looking at what portion of the element you're trying to click is highlighted in dev tools when you look at the surrounding elements.

4
  • Thanks for your time. None of the suggested solutions are working. I can tell for sure that this xpath is working just fine: driver.find_element_by_xpath("//*[@id='gcw-flights-form-hp-flight']/div[7]/label/button").click() But I still can't understand how and why it's working...
    – rodut
    May 23, 2019 at 19:51
  • Interesting, do you get a different error when trying to click the span? Or is it still ElementNotInteractableException?
    – mrfreester
    May 23, 2019 at 22:01
  • Yikes, judging by when the icon switches to the hand I think you need to click the label instead... What a gross element! //button[@id='search-button-hp-package']/.. I'll update the answer
    – mrfreester
    May 23, 2019 at 22:06
  • Same error every time: selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable The last code doesn't work :/
    – rodut
    May 24, 2019 at 6:28
0

Try this in the console if it is working use it of the website $x("//*[@id='search-button-hp-package']/span")

0

The error you are getting is because there would another element overlapping the element you want to click on. Please look at the dom of the website and find out what that element is. Please debug the script you are writing and make sure there no pop ups or any other kind of objects overlapping the element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.