Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Selenium by (19.7k points)
recategorized by

I am trying to click an element in Selenium.

url = "http://www.google.com"

The xpath for the element is: url = //div[@class='filter offices']

Here is my code:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get(url)

element = driver.find_element_by_xpath("//div[@class='filter offices']")

element.click()

When I click the element, the drop-down for offices should appear. Instead, when I click the element, nothing happens. What am I doing wrong?

1 Answer

0 votes
by (62.9k points)

Below is a working script that selects a location.

from selenium import webdriver

import time

driver = webdriver.Chrome('./chromedriver.exe')

url="https://www.intellipaat.com"

try:

    driver.get(url)

    element = driver.find_element_by_xpath("//div[@class='filter offices']")

    element.click()

    time.sleep(5)

    element = driver.find_element_by_xpath("//input[@id='search_offices_chicago']")

    element.click()

    time.sleep(5)

except Exception as e:

    print e

    driver.quit()

driver.quit()

Hope this helps!

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing certification!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...