读取ini文件后查看元素,打印结果时一直提示AttributeError: 'str' object has no attribute 'find_element_by_xpath',哪位大神帮忙看下哪里出了问题,感谢
from base.read_ini import *
class FindElement(object):
def __init__(self, driver):
self.driver = driver
def find_element(self, key):
read_ini = ReadIni()
data = read_ini.get_register_element(key)
by = data.split(">")[0]
values = data.split(">")[1]
# try:
if by == "id":
return self.driver.find_element_by_id(values)
elif by == "xpath":
return self.driver.find_element_by_xpath(values)
elif by == "classname":
return self.driver.find_element_by_class_name(values)
# except:
# return None
if name == "main":
ft = FindElement("driver")
fl = ft.find_element("username")
print(fl)
你 self.driver 的值是字符串 "driver",肯定没有 "find_element_by_xpath" 方法啊