硒的智能定位器类。

selenium-smart-locator的Python项目详细描述


硒智能定位器

Build StatusCoverage StatusCode Health

类封装硒定位器的生成。

它的设计是简单和直观的使用。它提供了各种方法来生成 硒兼容定位器。该类可用于selenium元素查询。

loc=Locator(By.XPATH,'//foo/bar/baz')# Old selenium way of doing itelement=s.find_element(*loc)# Expand the tuple. That's how to use the class.

这是它工作原理的基本示例。下面是简化定位器的使用示例:

# When you use this simple format of CSS consisting of tag name, ids and classes, it gets# detected automatically and the result is a CSS selector. IDs and classes are optional.Locator('div#foo.bar.baz')# => Locator(by='css selector', locator='div#foo.bar.baz')# When you specify a plain string and it does not get matched be the preceeding CSS detector# it is assumed it is an XPath expressionLocator('//h1')# => Locator(by='xpath', locator='//h1')# If you pass a Locator instance, it just goes straight throughLocator(Locator('//h1'))# => Locator(by='xpath', locator='//h1')# If you have your own object, that implements __locator__(), then it can also be resolved# by the class. The __locator__() must either return Locator instance or# anything that Locator can process.Locator(my_obj)# You can leverage kwargs to say strategy=locatorLocator(xpath='//h1')# => Locator(by='xpath', locator='//h1')Locator(css='#something')# => Locator(by='css selector', locator='#something')Locator(by='xpath',locator='//h1')# => Locator(by='xpath', locator='//h1')# For your comfort, you can pass a dictionary, like it was kwargsLocator({'by':'xpath','locator':'//h1'})# => Locator(by='xpath', locator='//h1')# You can also use Locator's classmethods, like this:Locator.by_css('#foo')# => Locator(by='css selector', locator='#foo')# Always in format Locator.by_<strategy_name>

当您有定位器时,可以使用方便的方法避免使用*

l=Locator('#foo')browser=Firefox()element=l.find_element(browser)elements=l.find_elements(browser)

如您所见,指定输入参数的方法有很多,给您提供了很大的自由度 你想如何构造你的定位器。你可以把它们储存在山药里 解析条目的定位器。或者别的什么。

可用的选择策略:

  • 类名
  • css
  • id
  • 链接文本
  • 姓名
  • 部分链接文本
  • 标签
  • xpath

许可证

根据GPLv3授权

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javascript问题:通过URL用网站数据填充Textview   java TabLayout Android,如何用几个标签填充整个屏幕宽度,并用大量标签滚动?   Eclipse Java运行的文件不再存在于我的工作区中   安装两个Java版本时,使用Java的windows链接不起作用   java将多个图形添加到单个JPanel   java Kafka ConsumerFactory,带有两个Desiarizer   使用反射更改java类超类   当一致性测试失败时,java有没有办法让堆栈跟踪显示在控制台中   java映射到基元类型的HashMap的快速替代方案是什么?   java关闭一个jframe所有剩余的打开jframe都将关闭。   java为什么不推荐“使用getString()获取设备标识符”?   java值比较和值赋值之间有什么性能差异吗?   Java实体数组到JavaScript数组   java使用流将一个列表转换为另一个列表   在JTree中保存对象,但更改显示的名称(java swing)?   java“Hello world”Android应用程序,文件尽可能少,没有IDE,只有文本编辑器   java在方法之间传递值   java如何为项目数组创建ParseQuery?