I want to select all the rows in a table that have class name either TCP_RowOdd
or TCP_RowEven
.
Currently, I am doing it like this
oddRows = driver.find_elements_by_class_name("TCP_RowOdd")
evenRows = driver.find_elements_by_class_name("TCP_RowEven")
Is there an OR clause that can be used here to do it in a single query.
The first element with the link text value matching the location will be returned. The first element with the partial link text value matching the location will be returned. The first element with the given tag name will be returned. the first element with the matching class attribute name will be returned.
The . find_element_by_class_name() method only returns the first element with the matching class. It raises a NoSuchElementException if no element exists with the given class name.
We can find an element using the attribute id with Selenium webdriver using the locators - id, css, or xpath. To identify the element with css, the expression should be tagname[id='value'] and the method to be used is By. cssSelector. To identify the element with xpath, the expression should be //tagname[@id='value'].
Exceptions in Selenium Python are generally classified into two types. Checked Exception handling in Selenium is conducted while writing the code. On the other hand, Unchecked Exceptions are raised during runtime and can generate fatal errors compared to the former type of exception.
There are multiple ways to that, I prefer the CSS selector:
rows = driver.find_elements_by_css_selector(".TCP_RowOdd,.TCP_RowEven")
The comma in the selector means "or".
Or, we can grab all elements having a class that starts with TCP_Row
:
rows = driver.find_elements_by_css_selector("[class^=TCP_Row]")
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