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)')]"
Community
  • 1
  • 1
Celi Manu
  • 371
  • 2
  • 7
  • 19
  • Possible duplicate of [Selenium Expected Conditions - possible to use 'or'?](http://stackoverflow.com/questions/16462177/selenium-expected-conditions-possible-to-use-or) – Random Davis Dec 22 '16 at 22:10
  • Please post the HTML of the button in the off state and both on states (hex and rgb colors). – JeffC Dec 22 '16 at 23:01

1 Answers1

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.

Community
  • 1
  • 1
JeffC
  • 22,180
  • 5
  • 32
  • 55