How to get same class name seperately by using css_selector?


I am using the below code to get data from Two table elements have the same class name. How can I get just one of them?

from selenium import webdriver
import time

driver_path = "C:\\Users\\Bacanli\\Desktop\\chromedriver.exe"
browser = webdriver.Chrome(driver_path)

Krediler = browser.find_element_by_xpath("//*[@id='tabloListesiItem-253']/span")

elements = browser.find_elements_by_css_selector("td.ortala")

for element in elements:



If you want to select all rows for one column only that match a specific css selection, then you can use :nth-child() selector.

Simply, the code will be like this:

elements = browser.find_elements_by_css_selector("td.ortala:nth-child(2)")

In this way, you will get the "Krediler" column rows only. You can also select the first child if you want to by applying the same idea.

Answered By – Hussein Basil

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published