Home > database >  Not able to click on a button on Python Selenium
Not able to click on a button on Python Selenium

Time:11-17

I need to click on the Flight button on this flight website https://www.expedia.com/, but i do not know how. Tried to find the id on Inspect but couldn't. How can I click on the Flight Button on PyCharm.

from selenium import webdriver


driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")

driver.maximize_window()  
driver.get("https://www.expedia.com/")

driver.find_element_by_class_name("Flights").click()

CodePudding user response:

The Flights attribute doesn't have class name as Flights. It has text Flights

HTML:

<span class="uitk-tab-text">Flights</span>

Code:

driver.find_element_by_xpath("//span[text()='Flights']").click()

Always check your xPath in chrome console to make sure it is unique.

  • Press F12 in Chrome.
  • Go to elements section
  • Search ( CTRL F)
  • Place the xpath and see, if your desired element is getting highlighted with 1/1 matching node. This means, your xPath is unique.
  • Related