首页 新闻 会员 周边 捐助

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

0
悬赏园豆:20 [待解决问题]

读取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)
年少可曾轻狂的主页 年少可曾轻狂 | 初学一级 | 园豆:182
提问于:2021-02-22 14:51
< >
分享
所有回答(1)
1

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

baogao_pro | 园豆:619 (小虾三级) | 2021-02-23 16:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册