我用selenium+python登录百度用户名登录跳不过去?
那个不应该有多标签切换操作,但无论用什么定位都无法定位,有大神解释一下吗from commonlib.Commonlib import Common
import time
class baidu_login(Common):
def login(self,user,pwd):
self.open_url("https://www.baidu.com/")
#点击登录按钮
self.click("link","登录")
time.sleep(2)
#点击用户名登录按钮(百度上有两个登陆方式,一个是扫码的,一个是用户名登录)
self.click("css","#TANGRAM__PSP_10__footerULoginBtn")
self.input_data("id","TANGRAM__PSP_10__userName",user)
self.input_data("id","TANGRAM__PSP_10__password",pwd)
self.click("id","TANGRAM__PSP_10__submit")以下是调用的函数
def LocateElement(self,locate_type,value):
el=None
if locate_type=="id":
el=self.driver.find_element_by_id(value)
elif locate_type=="name":
el=self.driver.find_element_by_name(value)
elif locate_type=="class":
el=self.driver.find_element_by_class_name(value)
elif locate_type=="link":
el=self.driver.find_element_by_link_text(value)
elif locate_type=="tag":
el=self.driver.find_element_by_tag_name(value)
elif locate_type=="xpath":
el=self.driver.find_element_by_xpath(value)
elif locate_type=="partial":
el=self.driver.find_element_by_partial_link_text(value)
elif locate_type=="css":
el=self.driver.find_element_by_css_selector(value)
if locate_type is not None:
return el
测试 定位问题 抓抓前端包看看 emmm...代码里没用到函数啊,可以全换成Xpath定位
页:
[1]