A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/SeleniumHQ/seleniumhq.github.io/commit/759fdeec9d32221e669ea5dd1fcac9d726686b0c below:

organize element documentation (#876) [deploy site] · SeleniumHQ/seleniumhq.github.io@759fdee · GitHub

File tree Expand file treeCollapse file tree 28 files changed

+4462

-5167

lines changed

Filter options

Expand file treeCollapse file tree 28 files changed

+4462

-5167

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1,34 @@

1 +

---

2 +

title: "Tips on working with locators"

3 +

linkTitle: "Locators"

4 +

weight: 8

5 +

description: >

6 +

When to use which locators and how best to manage them in your code.

7 +

---

8 + 9 +

Take a look at examples of the [supported locator strategies]({{< ref "/documentation/webdriver/elements/locators.md" >}}).

10 + 11 +

In general, if HTML IDs are available, unique, and consistently

12 +

predictable, they are the preferred method for locating an element on

13 +

a page. They tend to work very quickly, and forego much processing

14 +

that comes with complicated DOM traversals.

15 + 16 +

If unique IDs are unavailable, a well-written CSS selector is the

17 +

preferred method of locating an element. XPath works as well as CSS

18 +

selectors, but the syntax is complicated and frequently difficult to

19 +

debug. Though XPath selectors are very flexible, they are typically

20 +

not performance tested by browser vendors and tend to be quite slow.

21 + 22 +

Selection strategies based on _linkText_ and _partialLinkText_ have

23 +

drawbacks in that they only work on link elements. Additionally, they

24 +

call down to XPath selectors internally in WebDriver.

25 + 26 +

Tag name can be a dangerous way to locate elements. There are

27 +

frequently multiple elements of the same tag present on the page.

28 +

This is mostly useful when calling the _findElements(By)_ method which

29 +

returns a collection of elements.

30 + 31 +

The recommendation is to keep your locators as compact and

32 +

readable as possible. Asking WebDriver to traverse the DOM structure

33 +

is an expensive operation, and the more you can narrow the scope of

34 +

your search, the better.

Original file line number Diff line number Diff line change

@@ -0,0 +1,27 @@

1 +

---

2 +

title: "Tips on working with locators"

3 +

linkTitle: "Locators"

4 +

weight: 8

5 +

needsTranslation: true

6 +

description: >

7 +

When to use which locators and how best to manage them in your code.

8 +

---

9 + 10 +

Take a look at examples of the [supported locator strategies]({{< ref "/documentation/webdriver/elements/locators.md" >}}).

11 + 12 +

一般に、HTMLのid属性が利用可能でユニークかつ一貫している場合、ページで要素を探す方法として適しています。

13 +

idは動作がとても速い傾向があり、複雑なDOMトラバースに伴う処理を省略できます。

14 + 15 +

ユニークなidが使えない場合、きれいに書かれたCSSセレクタが要素を探す方法として適しています。

16 +

XPathはCSSセレクタと同様に動作しますが、シンタックスは複雑で大抵の場合デバッグが困難です。

17 +

XPathはとても柔軟ですが、ブラウザベンダは性能テストを通常行っておらず、非常に動作が遅い傾向があります。

18 + 19 +

link textセレクタとpartial _linkText_ セレクタはa要素でしか動作しないという欠点があります。

20 +

加えて、これらはWebDriverの内部でXPathの呼び出しに置き換えられます。

21 + 22 +

タグ名によるロケータは危険な方法になり得ます。

23 +

大抵の場合ページ上には同じタグ名の要素が複数あります。タグ名は要素のコレクションを返す _findElements(By)_ メソッドを使う時にもっとも役に立ちます。

24 + 25 +

ロケータは可能な限り簡潔に、読みやすい状態を保つことを推奨します。

26 +

WebDriverでDOM構造のトラバースを行うのは重い処理となります。

27 +

検索の範囲を狭めた方がより良い結果を得られます。

Original file line number Diff line number Diff line change

@@ -0,0 +1,34 @@

1 +

---

2 +

title: "Tips on working with locators"

3 +

linkTitle: "Locators"

4 +

weight: 8

5 +

needsTranslation: true

6 +

description: >

7 +

When to use which locators and how best to manage them in your code.

8 +

---

9 + 10 +

Take a look at examples of the [supported locator strategies]({{< ref "/documentation/webdriver/elements/locators.md" >}}).

11 + 12 +

No geral, se os IDs de HTML estiverem disponíveis, únicos e consistentemente

13 +

previsíveis, eles são o método preferido para localizar um elemento

14 +

uma página. Eles tendem a trabalhar muito rapidamente e dispensar muito processamento

15 +

que vem com travessias de DOM complicadas.

16 + 17 +

Se IDs exclusivos não estiverem disponíveis, um seletor CSS bem escrito é o

18 +

método preferido de localização de um elemento. XPath funciona bem como CSS

19 +

seletores, mas a sintaxe é complicada e frequentemente difícil de

20 +

depurar. Embora os seletores XPath sejam muito flexíveis, eles não são tipicamente testados em performance por fornecedores de navegadores e tendem a ser bastante lentos.

21 + 22 +

As estratégias de seleção baseadas em _linkText_ e _partialLinkText_ têm

23 +

desvantagens porque eles só funcionam em elementos de link. Além disso, eles

24 +

chamam seletores XPath internamente no WebDriver.

25 + 26 +

O nome da tag pode ser uma maneira perigosa de localizar elementos. tem

27 +

frequentemente, vários elementos da mesma tag presentes na página.

28 +

Isso é útil principalmente ao chamar o método _findElements(By) _ que

29 +

retorna uma coleção de elementos.

30 + 31 +

A recomendação é manter seus localizadores compactos e

32 +

legíveis quanto possível. Pedir ao WebDriver para percorrer a estrutura DOM

33 +

é uma operação cara, e quanto mais você pode restringir o escopo de

34 +

sua pesquisa, melhor.

Original file line number Diff line number Diff line change

@@ -0,0 +1,20 @@

1 +

---

2 +

title: "Tips on working with locators"

3 +

linkTitle: "Locators"

4 +

weight: 8

5 +

needsTranslation: true

6 +

description: >

7 +

When to use which locators and how best to manage them in your code.

8 +

---

9 + 10 +

Take a look at examples of the [supported locator strategies]({{< ref "/documentation/webdriver/elements/locators.md" >}}).

11 + 12 +

一般来说,如果 HTML 的 id 是可用的、唯一的且是可预测的,那么它就是在页面上定位元素的首选方法。它们的工作速度非常快,可以避免复杂的 DOM 遍历带来的大量处理。

13 + 14 +

如果没有唯一的 id,那么最好使用写得好的 CSS 选择器来查找元素。XPath 和 CSS 选择器一样好用,但是它语法很复杂,并且经常很难调试。尽管 XPath 选择器非常灵活,但是他们通常未经过浏览器厂商的性能测试,并且运行速度很慢。

15 + 16 +

基于链接文本和部分链接文本的选择策略有其缺点,即只能对链接元素起作用。此外,它们在 WebDriver 内部调用 XPath 选择器。

17 + 18 +

标签名可能是一种危险的定位元素的方法。页面上经常出现同一标签的多个元素。这在调用 _findElements(By)_ 方法返回元素集合的时候非常有用。

19 + 20 +

建议您尽可能保持定位器的紧凑性和可读性。使用 WebDriver 遍历 DOM 结构是一项性能花销很大的操作,搜索范围越小越好。

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4