你好,python类是需要初始化的,你没有执行初始化就开始调用函数出错了,代码做如下修改即可
from selenium.webdriver.chrome import webdriver
from selenium.webdriver.firefox import webdriver
from selenium import webdriver
class PageElements:
"""
浏览器元素
"""
def __init__(self):
print("y")
def chrome_ele(self):
"""
谷歌
:return:
"""
chr_driver = webdriver.Chrome()
self.user_name = chr_driver.find_element_by_id("kw")
self.pdw = chr_driver.find_element_by_id('loginpwd')
self.login_btn = chr_driver.find_element_by_id('loginBtn')
def ie_ele(self):
"""
ie
:return:
"""
ie_driver = webdriver.Ie()
self.ie_usen = ie_driver.find_element_by_id("loginUserName")
self.ie_usepwd = ie_driver.find_element_by_id("loginPwd")
self.ielogin_btn = ie_driver.find_element_by_id("loginBtn")
pass
def firefox_ele(self):
"""
firefox
:return:
"""
fire_driver = webdriver.Firefox()
self.fire_usen = fire_driver.find_element_by_id("loginUserName")
self.fire_usepwd = fire_driver.find_element_by_id("loginPwd")
self.firelogin_btn = fire_driver.find_element_by_id("loginBtn")
pass
def edge_ele(self):
"""
edge
:return:
"""
edeg_driver = webdriver.Edge()
self.edge_usen = edeg_driver.find_element_by_id("loginUserName")
self.edge_useped = edeg_driver.find_element_by_id("loginPwd")
self.edgelogin_btn = edeg_driver.find_element_by_id("loginBtn")
PageElementsobjec=PageElements()
chrome_ele = PageElementsobjec.chrome_ele()
ie_ele = PageElementsobjec.ie_ele()
fire_ele = PageElementsobjec.firefox_ele()
edge_ele = PageElementsobjec.edge_ele()
有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力