1

Using selenium and python to create some GUI tests. I'm testing to make sure a button is present and blue ("active") before clicking on it...but sometimes the color is hex and sometimes it's rgb, so I need to check either one of those in my web driver wait.

Here's what I have:

xpath = str(locator) + "[contains(@style, 'background: rgb(223, 239, 252)')]"

WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, xpath)))

Now this works, but I want to add OR 'background: #2E6E9E' as a condition to move on from the wait.

I used this post to find out how to condition a wait on a css style.

Also, an example of what would be passed into locator would be

"//button[@id='button1']"

So xpath would be

"//button[@id='button1'][contains(@style, 'background: rgb(223, 239, 252)')]"
2

1 Answer 1

1

There are a few ways you can accomplish this. You can go down the path you are looking at now and use an OR with either a CSS Selector or an XPath. These are well documented.

Another option is create a custom wait. An example of this is documented in this answer. You could take advantage of element.value_of_css_property("background") which returns a string in an rgb format. Even if the format is specified in hex, it will return rgb so you won't need an OR in this case. You can also use the Selenium color support module documented here.

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.