硒的智能定位器类。

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第三方库


热门话题
java Synth外观和感觉什么都不做?   java为什么JavaFX在使用文本组件时会在字母之间添加额外的间距?我该如何修复它?   java四位数字程序:分组数字   java我应该如何创建这个新页面?JSP还是servlet?   java将hashmap作为avalue添加到hashmap中   java如何使xmemcached更快   一个流中的java筛选器和set()   EJB模块和HTTP路由器模块之间的java通用绑定   java线程处理多个rest调用   java什么是运算符重载,它与多态性不同吗?   java投票系统错误