2016-03-31 20 views
1

Öğemde bir metin olup olmadığını doğrularım. Metin dizede bir alıntı içerir. Benim yöntemim yanlış olduğunu iddia ediyor. Doğru olmasını bekliyorum çünkü metin GUI'de var.Selenium Python dizgideki alıntılar atma hatası veriyor

Alıntıyı dizeye düzgün şekilde dahil etmiyorum. Doğru sözdizimi nedir lütfen?

i diyor debugger kullanarak kodlarını incelemek zaman:

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

Benim yöntemdir:

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?" 

alıntı ile dizesidir: Bir veya daha fazla raporu 'varsayılan' kullanmak önek ve üzerine yazılacaktır. Devam etmek ister misiniz?

Ben

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

denedim ve ben denedim:

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

HTML:

<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 

Teşekkür, Riaz

+0

'Do' önce kasıtlı Bu çift aralık mı? – alecxe

+0

'overwritten_element.text' tam değeri nedir? – alecxe

+0

html'yi incelediğimde, –

cevap

0

Benzer bir sınama oluşturduktan sonra, bu sorun tırnak işaretleri ile değil, çift boşlukla ortaya çıkar. 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 

yukarıdaki test çıkışları

,

>  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 
İlgili konular