美文网首页selenium seldom框架
seldom学习(三):seldom 定位元素方法

seldom学习(三):seldom 定位元素方法

作者: 一如既往而已 | 来源:发表于2020-05-13 16:59 被阅读0次

seldom 定位元素方法(对比Selenium)

seldom 提供了8中定位方式,与Selenium保持一致。

  • id_
  • name
  • class_name
  • tag
  • link_text
  • partial_link_text
  • css
  • xpath

使用方式

import seldom

class YouTest(seldom.TestCase):

    def test_case(self):
        """a simple test case """
        self.open("https://www.baidu.com")
        self.type(id_="kw", text="seldom")
        self.click(css="#su")
        self.assertTitle("seldom_百度搜索")

点击click()和输入type()的时候直接使用。

帮助信息:

定位一组元素

有时候我们通过一种定位写法不能找到单个元素,需要在一种定位方式中使用下标,在seldom中可以通过index指定下标。

  • selenium中的写法
driver.find_elements_by_tag_name("input")[7].send_keys("selenium")
  • seldom中的写法
self.type(tag="input", index=7, text="seldom")

在seldom中不指定index默认下标为0

8种定位用法

<form id="form" class="fm" action="/s" name="f">
    <span class="bg s_ipt_wr quickdelete-wrap">
        <input id="kw" class="s_ipt" name="wd">

定位方式:

self.type(id_="kw", text="seldom")
self.type(name="wd", text="seldom")
self.type(class_name="s_ipt", text="seldom")
self.type(tag="input", text="seldom")
self.type(link_text="hao123", text="seldom")
self.type(partial_link_text="hao", text="seldom")
self.type(xpath="//input[@id='kw']", text="seldom")
self.type(css="#kw", text="seldom")

相关文章

网友评论

    本文标题:seldom学习(三):seldom 定位元素方法

    本文链接:https://www.haomeiwen.com/subject/iofonhtx.html