Issue using XPath



  • I'm having an issue. 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? Thank you.



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2