selenium2 页面元素
2021-07-02 17:08 更新
element.py
类大致是这样的:
from selenium.webdriver.support.ui import WebDriverWait
class BasePageElement(object):
"""初始化每个页面对象类的基本页类"""
def __set__(self, obj, value):
"""用给定的值设置文本"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element_by_name(self.locator))
driver.find_element_by_name(self.locator).send_keys(value)
def __get__(self, obj, owner):
"""从具体的对象里获取文本"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element_by_name(self.locator))
element = driver.find_element_by_name(self.locator)
return element.get_attribute("value")
以上内容是否对您有帮助:
更多建议: