I use Selenium WebDriver to scrape a table taken from a web page, written in JavaScript.
I am iterating on a list of table rows. Each row may be of a different class. I want to get the name of this class so that I can choose appropriate action for each row.
table_body = table.find_element_by_tag_name('tbody')
rows = table_body.find_elements_by_tag_name('tr')
for row in rows:
if (row.GetClassName()=="date"):
Action1()
else:
Action2()
Is this possible with Selenium? Or suggest another approach.
We can find an element using the attribute class name with Selenium webdriver using the locators - class name, css, or xpath. To identify the element with css, the expression should be tagname[class='value'] and the method to be used is By. cssSelector.
We can select a drop-down menu option value with Selenium webdriver. The Select class in Selenium is used to handle drop-down. In an html document, the drop-down is identified with the <select> tag. Let us see the html structure of a drop-down.
This class provides a mechanism to represent them as objects & perform various actions on the related elements. Typically, the findElement method in remoteDriver returns an object of class webElement.
.get_attribute()
method is what you are looking for:
row.get_attribute("class")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With