Can we select elements by CSS selectors in Python Selenium Webdriver?

0 votes
Can we select elements by CSS selectors in Python Selenium Webdriver?
Jul 23 in Selenium by Suhana
30 views

1 answer to this question.

0 votes

Hi Suhana, you can use CSS Selectors like class, id, label, link etc to select elements in Python Selenium Webdriver. Following code snippet shows how to use them:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
from selenium.common.exceptions import NoSuchElementException
from pip._vendor.distlib import resources

driver = webdriver.Firefox()
driver.get("https://www.flipkart.com/")

sleep(20)

try:
    driver.find_element_by_css_selector("li.login").click()
except NoSuchElementException:
    print("Element not found")

sleep(5)

driver.quit()

answered Jul 29 by Abha
• 19,130 points

Related Questions In Selenium

0 votes
1 answer

How to find Elements by their Attribute in Python Selenium WebDriver

To find all the <td> tags which have attribute data-sortable-id you ...READ MORE

answered Jul 19, 2018 in Selenium by Samarpit
• 5,130 points
1,561 views
0 votes
1 answer
+2 votes
1 answer

How can we handle authentication popup in Selenium WebDriver using Java

The Alert Method, authenticateUsing() lets us skip ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,610 points
5,560 views
0 votes
1 answer
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8 in Selenium by Anvi
• 11,690 points
108 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
406 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
762 views
0 votes
1 answer
0 votes
1 answer