1

I am verifying if some text is present in my element. The text includes a quote in the string. My method is asserting False. I am expecting it to be True because the text is there on the GUI.

I am not including the quote properly in the string. What is the correct syntax please?

When i inspect the code using the debugger it says:

overwritten_element.text = {unicode} u'One or more reports use the \\'default\\'prefix and will be overwritten.  Do you wish to continue?

My method is:

def is_save_overwrite_dialog_displayed(self): 
        overwritten_element = self.get_element(By.ID, 'message_dialog_question_content')
        return overwritten_element.text == r"One or more reports use the 'default' prefix and will be overwritten.  Do you wish to continue?"

The string with the quote is: One or more reports use the 'default' prefix and will be overwritten. Do you wish to continue?

I have tried

r"One or more reports use the 'default' prefix and will be overwritten.  Do you` wish to continue?"

and I have tried:

r"One or more reports use the \\'default\\' prefix and will be overwritten.  Do you wish to continue?"

The HTML is:

<div id="message_dialog_question_content">
<div>One or more reports use the 'default' prefix and will be overwritten.  Do you wish to continue?</div>
</div>

get_element

# returns the element if found
def get_element(self, how, what):
    # params how: By locator type
    # params what: locator value
    try:
        element = self.driver.find_element(by=how, value=what)
    except NoSuchElementException, e:
        print what
        print "Element not found "
        print e
        screenshot_name = how + what + get_datetime_now() # create screenshot name of the name of the element + locator + todays date time.  This way the screenshot name will be unique and be able to save
        self.save_screenshot(screenshot_name)
        raise
    return element

Thanks, Riaz

Riaz Ladhani
  • 3,946
  • 15
  • 70
  • 127

1 Answers1

0

Having created a similar test it reveals the problem is not with the quotes but with the double space. Spaces in HTML are compacted.

from splinter import Browser


def test_dummy():
    with Browser() as browser:
        browser.visit("http://localhost:8888/index.html")
        elem = browser.find_by_id("message_dialog_question_content")

        compare = r"One or more reports use the 'default' prefix and will be overwritten.  Do you wish to continue?"
        print "length of elem : {}, length of compare : {}".format(len(elem.text), len(compare))

        assert elem.text == compare

The above test outputs,

>       assert elem.text == compare
E       assert 'One or more ... to continue?' == 'One or more r... to continue?'
E         Skipping 60 identical leading characters in diff, use -v to show
E         - rwritten. Do you wish to continue?
E         + rwritten.  Do you wish to continue?
E         ?           +
---------- Captured stdout call ----------
length of elem : 94, length of compare : 95
Community
  • 1
  • 1
sowa
  • 1,249
  • 16
  • 29