公共和私有选择器方法之间的区别 [英] Difference Between Public and Private Selector Methods

查看:41
本文介绍了公共和私有选择器方法之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在阅读这里的文档并且很好奇:在这种情况下,公共方法和私有方法有什么区别?

I'm just reading this documentation here and was curious: What is the difference between public and private methods in this context?

要查找多个元素(这些方法将返回一个列表):

To find multiple elements (these methods will return a list):

find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector

除了上面给出的公共方法之外,还有两个私有方法可能对页面对象中的定位器有用.这是两个私有方法:find_element 和 find_elements.

find_elements_by_name
find_elements_by_xpath
find_elements_by_link_text
find_elements_by_partial_link_text
find_elements_by_tag_name
find_elements_by_class_name
find_elements_by_css_selector

Apart from the public methods given above, there are two private methods which might be useful with locators in page objects. These are the two private methods: find_element and find_elements.

我不明白为什么其中一些是公共方法,而另一些是私有方法,而且在任何地方都没有解释.

I don't understand why some of those are public methods, whereas others are private methods, and it isn't explained anywhere.

通过测试,我注意到公共和私有选择器的 FirefoxWebElement 存在差异.

From doing a test, I've noticed that there are differences in the FirefoxWebElement for public and private selectors.

<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="234a0c66-870f-4fee-92b5-8d10541f2d2d", element="3275635e-614d-42da-95ac-306b02743bec")>

session="234a0c66-870f-4fee-92b5-8d10541f2d2d"
element="3275635e-614d-42da-95ac-306b02743bec"

<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="c792073f-08b3-4519-a563-0f1e272a17e7", element="b61a6d2d-2c35-4872-a8e0-2649c189829b")>

session="c792073f-08b3-4519-a563-0f1e272a17e7"
element="b61a6d2d-2c35-4872-a8e0-2649c189829b"

推荐答案

如果看find_element_by_xpath

def find_element_by_xpath(self, xpath):
    return self.find_element(by=By.XPATH, value=xpath)

它使用 find_element 方法.现在为什么 find_element 被记录为私有?好几件事

It uses the find_element method. Now why is find_element documented as private? Well few things

  • 最初的开发人员认为有个人偏好以这种方式进行编码
  • 当您有使用 find_element_by_xpath 的源代码和使用 find_element(By.XPATH, "//div") 的源代码时,您会如何找到?令人困惑,所以最好保持一致
  • Python 通常以更像英语的方式使用,所以 find_element_by_xpath 清楚地解释了意图
  • 可以使用find_element 代替find_element_by_XXXX 吗?为什么不呢,在我的 selenium helper 库中,我只使用它.
  • The initial developer considered had personal preference to code it that way
  • How would you find when you have source codes using find_element_by_xpath and some using find_element(By.XPATH, "//div")? Confusing, so best is to just keep it consistent
  • Python is usually used in more english like manner, so find_element_by_xpath clear explains the intent
  • Can one use find_element instead of find_element_by_XXXX? Why not, In my selenium helper library I use that only.

所以这些都是我的想法,这些行的原始贡献者可能会说他的意图是将方法私有化

So those are my thoughts on the same, the original contributor to those line could probably tell his intentions were will making the method private

这篇关于公共和私有选择器方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆