Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (19.7k points)

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!

Browse Categories

...