4. Finds
乙醇 创建于 about 7 years 之前
最后更新: less than a minute 之前
阅读数: 207
webium.find.Finds
方法的用法跟Find
方法基本是一致的,不过返回的是WebElement
列表。
from selenium.webdriver.common.by import By
from webium import BasePage, Finds
class LinksPage(BasePage):
links = Finds(by=By.TAG_NAME, value='a')
def __init__(self):
super(LinksPage, self).__init__(url='http://itest.info')
if __name__ == '__main__':
page = LinksPage()
page.open()
print('Number of links: ' + str(len(page.links)))
我们甚至可以动态返回满足条件的一组元素。
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from webium import BasePage, Finds
class Link(WebElement):
def is_secure(self):
return self.get_attribute('href').startswith('https://')
class TypedPage(BasePage):
links = Finds(Link, By.TAG_NAME, 'a')
def __init__(self):
super(TypedPage, self).__init__(url='http://itest.info')
def get_unsecured_links(self):
return filter(lambda link: not link.is_secure(), self.links)
if __name__ == '__main__':
page = TypedPage()
page.open()
print('Number of unsecured links: ' + str(len(page.get_unsecured_links())))