网上的过期用法
username = driver.find_element_by_name('username')
login_form = driver.find_element_by_id('loginForm')
最新的有效用法
wd.find_element(By.XPATH, '//button[text()="Some text"]')
wd.find_element(By.ID, 'button')
wd.find_element(By.NAME, 'button')
有效用法示例
from selenium import webdriver
from selenium.webdriver.common.by import By
wd = webdriver.Chrome()
# 调用webpriver 对象的get方法 可以让浏览器打开指定网址
wd.get('https://www.baidu.com')
time.sleep(60)
wd.find_element(By.XPATH, '//button[text()="Some text"]')
wd.find_element(By.ID, 'button')
wd.find_element(By.NAME, 'button')
下面是 By 类的一些可用属性:
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
find_element使用By类的使用方式:
wd.find_element(LINK_TEXT, 'text1')
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。