如何验证selenium python中的元素是否为链接



如何检查给定元素是否链接,以及如何对元素执行操作(显示或启用元素(?

link=driver.find_element_by_id("btn-baseFooter-termsOfUse") #element 
if link.tag_name=='a': #validating the element 
print('element is link')
else:
print('element is text')
def TermAndPrivacyPolicy(self):
sleep(10)
terms=driver.find_element(By.ID, "btn-baseFooter-termsOfUse")
if terms.tag_name == 'a':
print('element is: ',terms.tag_name)
else:
print('element is not link it is: ',terms.tag_name)
if terms.is_displayed() and terms.is_enabled()==True:
terms.click()
print(terms.'link is enabled, displayed and link is clicked')
sleep(2)
element=driver.find_element(By.ID, 'btn-termsConditions-close')
driver.execute_script("arguments[0].scrollIntoView();", element)
element.click()
else:
print('Link is neither enable or displayed')

相关内容

  • 没有找到相关文章

最新更新