Python读取ini文件打印结果时提示AttributeError: 'str' object has no attribute 'find_element_by_xpath'

毕业设计客栈 其他问答 1

读取ini文件后查看元素,打印结果时一直提示AttributeError: 'str' object has no attribute 'find element by_xpath',哪位大神帮忙看下哪里出了问题,感谢

coding=utf-8

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)

回复

共1条回复 我来回复
  • 毕设项目助手
    这个人很懒,什么都没有留下~
    评论

    你 self.driver 的值是字符串 "driver",肯定没有 "find element by_xpath" 方法啊

    0条评论

发表回复

登录后才能评论