1
私の要素にテキストがあるかどうかを確認しています。テキストには、文字列内の引用符が含まれます。私の方法はFalseを主張している。 GUI上にテキストがあるので、それがTrueであることを期待しています。Selenium Pythonが文字列の引用符でエラーをスローしています
私は文字列に正しく引用符を含めていません。正しい構文はどうですか?
私は、デバッガを使用してコードを検査するとき、それは言う:
overwritten_element.text = {unicode} u'One or more reports use the \\'default\\'prefix and will be overwritten. Do you wish to continue?
私の方法は次のとおりです。
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?"
引用符付き文字列は次のとおりです。 つ以上のレポートは、「デフォルト」を使用します接頭辞は上書きされます。続行しますか?
私は
r"One or more reports use the 'default' prefix and will be overwritten. Do you` wish to continue?"
を試してみましたし、私が試してみました:
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
ありがとう、 Riaz
は意図的な 'Do'前に、この二重のスペースですか? – alecxe
'overwritten_element.text'の正確な値は何ですか? – alecxe
私はhtmlを調べるときに二重空間を持っています。 –