As per my Edit this is what I found to be a solution.
if isinstance(salesForceLink, object) == True:
print("sales Force link found")
else:
print("sales force link not found")
Edit: Per the first comment below I had found that while the statement equates to true, that really I was just doing double the work. my working solution is just two line using custom wrapped functions. the second one verifies the text after following the link.
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")
The custom functions are as follows for anyone interested:
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")
and
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"
The print debug function just takes takes in a bool and prints if true or false.
All of the variables that look like G.error, or G.debug are proxy global variables that are stored in an empty class for use throughout the many test i have.
I hope that helps.