0

I can't seem to find an answer for this on the net.

Here's a snippet of html code:

<td>
    <div class="low-fare-day active"></div>
    <div class="low-prices"></div>
</td>
<td>
    <div class="low-fare-day"></div>
    <div class="low-prices1"></div>
</td>

Below is my code:

I want to find the two classes low-fare-day and low-fare-day.active using css_selector, but couldn't get it working. Can anyone solve this puzzle for me?

fromdata = driver.find_elements_by_css_selector('div.low-fare-day','div.low-fare-day.active')

or

fromdata = driver.find_elements_by_css_selector('div.low-fare-day' | 'div.low-fare-day.active')

2
  • Do you mean elements that match both classes, or either? If both, div.low-fare-day.active should work as the selector. Commented Feb 16, 2016 at 15:11
  • yes, i need to match both classes. div.low-fare-day.active only returns the first prize 'low-prices'. does the second class "low-fare-day " having a blank space behind causing it to return only the first prize? Commented Feb 16, 2016 at 16:19

1 Answer 1

1

Try it:

driver.find_elements_by_css_selector('div[class*=low-fare-day]')

Explanation:

div[class*=low-fare-day] -> means you're looking for a div

div[class*=low-fare-day] -> you're selecting the class value inside the div selected before to compare values

*= after class means you will cath all that is equals or that contains the next value

div[class*=low-fare-day] -> the value to compare if the div's class contains it

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.