if isinstance(salesForceLink, object) == True:
print("sales Force link found")
else:
print("sales force link not found")
编辑:根据下面的第一条评论,我发现虽然这句话等于真的,但实际上我只是做了双倍的工作。我的工作方案是使用自定义包装函数的两行代码。第二个在链接之后验证文本。
findLink(sel, "div.row:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > a:nth-child(1)", "sales force link")
verifyText(sel, ".freebirdFormviewerViewHeaderTitle" , "Salesforce Feedback")
定制功能如下:
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")
和
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"
print debug函数只接收一个bool并在true或false时打印。
我希望这有帮助。