NikaTheKilla
NikaTheKilla

Reputation: 135

Not able to click on a button on Python Selenium

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()

Upvotes: 0

Views: 169

Answers (1)

Nandan A
Nandan A

Reputation: 2922

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.

Upvotes: 1

Related Questions