常见的定位方式参见:http://www.cnblogs.com/ranxf/p/7928732.html

1、ID定位(find_element_by_id)

<input class="easyui-textbox" id="userID" name="userID" size="29" data-options="required:true" type="text">
<input class="easyui-validatebox validatebox-text" id="password" name="password" value="" size="30" data-options="validType:'password'" type="password">

实现代码:

driver.find_element_by_id("userID").clear()
driver.find_element_by_id("userID").send_keys("")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("0000000")

2、CSS定位(find_element_by_css_selector)

页面标签:

<div id="xz-guide-system" class="xz-content-guide-btpanel-button xz-w-eq-h xz-cursor-hand">button</div>

实现代码

driver.find_element_by_css_selector("div[id='xz-guide-system']").click()  # ok 用标签名称+属性值
driver.find_element_by_css_selector("#xz-guide-system").click() # ok css用#号表示id标签属性

3、find_elements

上面的页面中多个(div class="panel-title")

<div class="panel-title" style="height: 24px; line-height: 24px;">设备</div>

设备属于第五个,采用CSS和find_elements定位方法如下“

device = driver.find_elements("css selector", ".panel-title")
print(device[4].text)
device[4].click()

4、Xpath绝对路径定位(find_element_by_xpath)

定位设备管理采用Xpath定位方法如下:

driver.find_element_by_xpath("//*[@id='accordion_child_manage']/div[1]/div[2]/ul/li[2]").click()
												

Selenium+Python定位实例的更多相关文章

  1. selenium+python定位元素方法

    定位元素方法 官网地址:http://selenium-python.readthedocs.org/locating-elements.html        这里有各种策略用于定位网页中的元素(l ...

  2. selenium+python定位元素的方法及使用

    selenium的八种定位方法 By.ID 通过id定位 By.CLASS_NAME 通过className定位 By.CSS_SELECTOR 通过CSS定位 By.LINK_TEXT 通过link ...

  3. 基础selenium+Python(定位、等待、打印)

    1.第一个脚本 # coding = utf-8 from selenium import webdriver browser = webdriver.Firefox() browser.get(&q ...

  4. selenium python 定位一组对象

    为什么定位一组对象? 定位一组对象的思想    在定位一组对象的过程中我们如何实现?以前的都是通过具体的对象定位,那么定位一组我们就需要通过css来定位   在单个定位对象中使用的是find_elem ...

  5. selenium python 第一个脚本

    为什么选择python?我的回答很简单,简单易学,功能强大! 下面看看python和selenium 2的结合是什么样子吧 一.第一个selenium python脚本: #coding = utf- ...

  6. python selenium expected_conditions使用实例

    今天正好虫师问到selenium python binding中support.expected_conditions的用法,顺手总结了一下,希望对大家有所帮助. 场景 Expected Condit ...

  7. 【转载】【selenium+Python WebDriver】之元素定位

    总结: 感谢: “煜妃”<Selenuim+Python之元素定位总结及实例说明> “Huilaojia123”<selenium WebDriver定位元素学习总结> “上海 ...

  8. selenium python 一些操作和定位收集

    (—)滚动条操作 python中selenium操作下拉滚动条方法汇总 selenium_webdriver(python)控制浏览器滚动条 selenium+Python(select定位) Sel ...

  9. 【转】【selenium+Python WebDriver】之元素定位不到解决办法

    感谢: 煜妃的<Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)> ClassName定位报错问题:<[Python] ...

随机推荐

  1. onSaveInstanceState

    我们已经分析过Activity的启动流程,从中也分析了Activity的生命周期.而其中有一个生命周期方法:onSaveInstanceState方法,今天我们主要讲解一下onSaveInstance ...

  2. Java四种会话跟踪技术

    1.cookie:2.session:3.隐藏表单域:4.URL重写

  3. asp 中创建日志打印文件夹

    string FilePath = HttpRuntime.BinDirectory.ToString(); string FileName = FilePath + "日志" + ...

  4. json写入到excel表

    1. 拼接返回的json数据 // 拼接需要下载报表的HTML,并返回html;reportHtml(reporttData) { let html = `<html xmlns:o=" ...

  5. 160530、memcached集群(spring集成的配置)

    第一步:在linux机或windows机上安装memcached服务端(server) linux中安装memcached:centos中命令 yum -y install memcached 如果没 ...

  6. 2017Summmer_上海金马五校 F题,G题,I题,K题,J题

    以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...

  7. Client IP Address Client Identification

    HTTP The Definitive Guide Early web pioneers tried using the IP address of the client as a form of i ...

  8. 剖析Docker文件系统:Aufs与Devicemapper

    http://www.infoq.com/cn/articles/analysis-of-docker-file-system-aufs-and-devicemapper Docker镜像 典型的Li ...

  9. linux 修改用户密码

    passwd 命令:用于对用户的密码进行管理,可以设置.修改.删除密码. 修改root用户的密码:$ sudo passwd root

  10. Selenium问题总结

    1.Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox b ...