selenium - webdriver - 定位一组元素

本文介绍使用Selenium进行网页自动化测试的方法,包括通过多种选择器定位页面元素,如ID、名称、链接文本等,并提供了一个完整的Python示例,展示如何利用Selenium在百度网站上搜索并获取结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

八种方法:

find_elements_by_id()
find_elements_by_name()
find_elements_by_class_name()
find_elements_by_tag_name()
find_elements_by_link_text()
find_elements_by_partial_link_text()
find_elements_by_xpath()
find_elements_by_css_selector()

  

实例:

from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
sleep(5)

texts = driver.find_elements_by_xpath("//div/h3/a")

for t in texts:
    print(t.text)

driver.quit()

  

运行结果:

selenium

selenium教程-90天从入门到高薪【学习必看】

Selenium - Web Browser Automation
Selenium_百度百科
Selenium - Web Browser Automation
官网
功能自动化测试工具——Selenium篇
自动化测试工具Selenium入门 - 优快云博客
python爬虫从入门到放弃(八)之 Selenium库的使用 - pytho..._博客园
selenium用法详解 - 道高一尺 - 博客园
selenium中文网 – selenium安装、selenium使用、selenium中文、...
selenium-优快云下载
selenium自动化测试资源整理(含所有版本chrome、chrome..._优快云博客
自动化测试_2017新编自动化测试selenium课程

selenium_"0基础"到熟练只要4个月_月薪过万不是梦

【亚马逊】买selenium就上Z.CN_亚马逊海外购大牌"惠"聚_一键真..

  

参考资料:http://www.testclass.net/selenium_python/elements/

转载于:https://www.cnblogs.com/studyddup0212/p/9029063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值