<p>根据我的编辑,这是我发现的一个解决办法。在</p>
<pre><code>if isinstance(salesForceLink, object) == True:
print("sales Force link found")
else:
print("sales force link not found")
</code></pre>
<p>编辑:根据下面的第一条评论,我发现虽然这句话等同于真的,但实际上我只是做了双倍的工作。我的工作解决方案是使用自定义包装函数的两行代码。第二个验证链接后的文本。在</p>
^{pr2}$
<p>对于感兴趣的用户,自定义函数如下:</p>
<pre><code>def findLink(browser, css, label="", type="link:", x=1):
if x == 0:
if findCss(browser, css, type="link:"):
link = findCss(browser, css)
label = element.text
type = element.get_attribute('type')
printDebug(type + ": \"" + label + "\" found")
return link
else:
G.errors += 1
G.log[G.errors] = G.page + "ERROR" + label + " not found"
#print("ERROR" + label + " not found")
elif x == 1:
if findCss(browser, css):
element = findCss(browser, css)
label = element.text
type = element.get_attribute('type')
element.click()
printDebug(type + ": \"" + label + "\" found")
else:
G.errors += 1
G.log[G.errors] = G.page + "ERROR" + label + " not found"
else:
printDebug("Last flag must be 0 or 1, 0 is default")
</code></pre>
<p>以及</p>
<pre><code>def verifyText(browser, css, textToCheck=""):
if findCss(browser, css):
element = findCss(browser, css)
elementText = element.text
else:
G.errors += 1
G.log[G.errors] = G.page + "ERROR text: Could not find element"
if textToCheck == "" and elementText != textToCheck:
printDebug('text: "' + elementText + '" element Not Empty ' )
return str(elementText)
elif textToCheck == "" and elementText == textToCheck:
printDebug("text: Element Empty")
elif elementText == textToCheck:
printDebug('text: "' + elementText + '" found')
return str(elementText)
elif elementText != textToCheck:
G.errors += 1
G.log[G.errors] = G.page + ' ERROR text: "' + textToCheck + '" does not match "' + elementText + '"'
else:
G.errors += 1
G.log[G.errors] = G.page + "ERROR text: Unexpected Text Search Error"
</code></pre>
<p>print debug函数只接受bool并打印true或false。
所有看起来像G.error或G.debug的变量都是代理全局变量,它们存储在一个空类中,以便在我的许多测试中使用。在</p>
<p>我希望这有帮助。在</p>