Selenium and Python using If statement

wildshroom

I am trying understand why an if else isn't working using Selenium and Python. I have tried several different variations, but I believe this should work and stubbornly, maybe blindly, keep coming back to it.

example:

    if (self.driver.find_element_by_class_name('product')).text == "FEATURED PRODUCTS":
        print "\nHome Pass"
    else:
        print "\nHome Fail"

Tried this as well

if self.driver.find_element_by_class_name("product-teaser-list").text in "Featured Products":

Each execution returns Fail and when using assert, below, the .text is found. So I know the text is found with this method.

assert "FEATURED PRODUCTS" in self.driver.find_element_by_class_name('product').text
Gaurang Shah

try this following code.

if "FEATURED PRODUCTS" in self.driver.find_element_by_class_name('product').text

If this isn't working try to debug that. something white space creates an issue. however given the assert statement is passing, following should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selenium Webdriver - using isDisplayed() in If statement is not working

From Dev

Assert statement in Selenium using C#

From Dev

Using Python Queue with a "with" statement

From Dev

Tips on using the with statement in Python

From Dev

Using a conditional 'with' statement in Python

From Dev

Python regex: using or statement

From Dev

Using Python Queue with a "with" statement

From Dev

Python if statement using Modulo

From Dev

Using faker with selenium and python

From Dev

Selenium using python

From Dev

Selenium using python

From Dev

Using PhantomJs with Python/Selenium

From Dev

Parsing JSON using Python and if statement

From Dev

Python if statement using CSV Data

From Dev

Infinite loop in python using for statement

From Dev

Using the with statement in Python 2.5: SyntaxError?

From Dev

Python error when using "not in" in a if statement?

From Dev

Using an if statement involving time in python

From Dev

Using the with statement in Python 2.5: SyntaxError?

From Dev

Python error when using "not in" in a if statement?

From Dev

Using output of a python expression in an if statement

From Dev

Select checkbox using Selenium with Python

From Dev

Selecting a Button Using Selenium Python

From Dev

submitting captcha with selenium using python

From Dev

Login to reddit using selenium python

From Dev

Using a variable in xpath in Python Selenium

From Dev

Python / Selenium - using a conditional in an xpath

From Dev

Using a variable in Python selenium XPATH

From Dev

Selecting a Button Using Selenium Python