Splinter find_by_css excluding a class item

class="conversation hasLabels read"

Hello, everyone, I am trying to access an unread email using a for loop and specifying a class

browser.find_by_css(.conversation.hasLabels.hasAttachments)

The problem here is some emails have class="read" so when the for loop executes, it takes all the read ones also but that is a problem since the emails don't have an unread element. For better understanding, I would like to access a class providing exclusive parameters.

Upvotes: 0

Views: 150

Answers (3)

SimfikDuke
SimfikDuke

Reputation: 1148

It can help you if I understood the essence of the problem correctly:

browser.find_by_xpath('//*[contains(@class, "conversation")][contains(@class, "hasLabels")][not(contains(@class, "read"))]')

Upvotes: 0

pguardiario
pguardiario

Reputation: 55002

You can just add a :not

.conversation.hasLabels.hasAttachments:not(.read)

Upvotes: 0

Apparently using the script this way grabs only what you ask so this solves my problem.

browser.find_by_css('div[class="conversation hasLabels hasAttachments"]')

Upvotes: 1

Related Questions