|
2708 | 2708 | </span></span></code></pre></div></div><div class="tab-pane fade" id=tabs-10-06 role=tabpanel aria-labelled-by=tabs-10-06-tab tabindex=10><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-Kotlin data-lang=Kotlin><span style=display:flex><span> <span style=color:#204a87;font-weight:700>import</span> <span style=color:#000>org.openqa.selenium.By</span>
|
2709 | 2709 | </span></span><span style=display:flex><span> <span style=color:#204a87;font-weight:700>val</span> <span style=color:#000>driver</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>ChromeDriver</span><span style=color:#000;font-weight:700>()</span>
|
2710 | 2710 | </span></span><span style=display:flex><span> <span style=color:#204a87;font-weight:700>val</span> <span style=color:#000>loc</span><span style=color:#000;font-weight:700>:</span> <span style=color:#000>WebElement</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>driver</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>findElement</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>By</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>xpath</span><span style=color:#000;font-weight:700>(</span><span style=color:#a40000>'</span><span style=color:#8f5902;font-style:italic>//input[@value='f']'))
|
2711 |
| -</span></span></span><span style=display:flex><span><span style=color:#8f5902;font-style:italic></span> </span></span></code></pre></div></div></div><h2 id=utilizing-locators>Utilizing Locators</h2><p>The FindElement makes using locators a breeze! For most languages, all you need to do is utilize <code>webdriver.common.by.By</code>, however in others it’s as simple as setting a parameter in the FindElement function></p><p><a href=/documentation/about/contributing/#moving-examples><span class=selenium-badge-code data-bs-toggle=tooltip data-bs-placement=right title="One or more of these examples need to be implemented in the examples directory; click for details in the contribution guide">Move Code</span></a></p><ul class="nav nav-tabs" id=tabs-11 role=tablist><li class=nav-item><button class="nav-link active" id=tabs-11-01-tab data-bs-toggle=tab data-bs-target=#tabs-11-01 role=tab data-td-tp-persist=java aria-controls=tabs-11-01 aria-selected=true> |
| 2711 | +</span></span></span><span style=display:flex><span><span style=color:#8f5902;font-style:italic></span> </span></span></code></pre></div></div></div><h2 id=utilizing-locators>Utilizing Locators</h2><p>The FindElement makes using locators a breeze! For most languages, |
| 2712 | +all you need to do is utilize <code>webdriver.common.by.By</code>, however in |
| 2713 | +others it’s as simple as setting a parameter in the FindElement function</p><p><a href=/documentation/about/contributing/#moving-examples><span class=selenium-badge-code data-bs-toggle=tooltip data-bs-placement=right title="One or more of these examples need to be implemented in the examples directory; click for details in the contribution guide">Move Code</span></a></p><ul class="nav nav-tabs" id=tabs-11 role=tablist><li class=nav-item><button class="nav-link active" id=tabs-11-01-tab data-bs-toggle=tab data-bs-target=#tabs-11-01 role=tab data-td-tp-persist=java aria-controls=tabs-11-01 aria-selected=true> |
2712 | 2714 | Java</button></li><li class=nav-item><button class=nav-link id=tabs-11-02-tab data-bs-toggle=tab data-bs-target=#tabs-11-02 role=tab data-td-tp-persist=python aria-controls=tabs-11-02 aria-selected=false>
|
2713 | 2715 | Python</button></li><li class=nav-item><button class=nav-link id=tabs-11-03-tab data-bs-toggle=tab data-bs-target=#tabs-11-03 role=tab data-td-tp-persist=csharp aria-controls=tabs-11-03 aria-selected=false>
|
2714 | 2716 | CSharp</button></li><li class=nav-item><button class=nav-link id=tabs-11-04-tab data-bs-toggle=tab data-bs-target=#tabs-11-04 role=tab data-td-tp-persist=ruby aria-controls=tabs-11-04 aria-selected=false>
|
|
2855 | 2857 | </span></span><span style=display:flex><span><span style=color:#000>shadow_root</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>shadow_host</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>shadow_root</span>
|
2856 | 2858 | </span></span><span style=display:flex><span><span style=color:#000>shadow_content</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>shadow_root</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>find_element</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>By</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>CSS_SELECTOR</span><span style=color:#000;font-weight:700>,</span> <span style=color:#4e9a06>'#shadow_content'</span><span style=color:#000;font-weight:700>)</span></span></span></code></pre></div></div><div class="tab-pane fade" id=tabs-04-03 role=tabpanel aria-labelled-by=tabs-04-03-tab tabindex=4><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-CSharp data-lang=CSharp><span style=display:flex><span><span style=color:#204a87;font-weight:700>var</span> <span style=color:#000>shadowHost</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>_driver</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FindElement</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>By</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>CssSelector</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>"#shadow_host"</span><span style=color:#000;font-weight:700>));</span>
|
2857 | 2859 | </span></span><span style=display:flex><span><span style=color:#204a87;font-weight:700>var</span> <span style=color:#000>shadowRoot</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>shadowHost</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>GetShadowRoot</span><span style=color:#000;font-weight:700>();</span>
|
2858 |
| -</span></span><span style=display:flex><span><span style=color:#204a87;font-weight:700>var</span> <span style=color:#000>shadowContent</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>shadowRoot</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FindElement</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>By</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>CssSelector</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>"#shadow_content"</span><span style=color:#000;font-weight:700>));</span></span></span></code></pre></div></div><div class="tab-body tab-pane fade" id=tabs-04-04 role=tabpanel aria-labelled-by=tabs-04-04-tab tabindex=4>shadow_host = @driver.find_element(css: '#shadow_host') |
2859 |
| -shadow_root = shadow_host.shadow_root |
2860 |
| -shadow_content = shadow_root.find_element(css: '#shadow_content')</div><div class="tab-pane fade" id=tabs-04-05 role=tabpanel aria-labelled-by=tabs-04-05-tab tabindex=4><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-JavaScript data-lang=JavaScript></code></pre></div></div><div class="tab-pane fade" id=tabs-04-06 role=tabpanel aria-labelled-by=tabs-04-06-tab tabindex=4><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-Kotlin data-lang=Kotlin></code></pre></div></div></div><h3 id=optimized-locator>Optimized locator</h3><p>A nested lookup might not be the most effective location strategy since it requires two |
| 2860 | +</span></span><span style=display:flex><span><span style=color:#204a87;font-weight:700>var</span> <span style=color:#000>shadowContent</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>shadowRoot</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FindElement</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>By</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>CssSelector</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>"#shadow_content"</span><span style=color:#000;font-weight:700>));</span></span></span></code></pre></div></div><div class="tab-pane fade" id=tabs-04-04 role=tabpanel aria-labelled-by=tabs-04-04-tab tabindex=4><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-Ruby data-lang=Ruby><span style=display:flex><span><span style=color:#000>shadow_host</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>@driver</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>find_element</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>css</span><span style=color:#000;font-weight:700>:</span> <span style=color:#4e9a06>'#shadow_host'</span><span style=color:#000;font-weight:700>)</span> |
| 2861 | +</span></span><span style=display:flex><span><span style=color:#000>shadow_root</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>shadow_host</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>shadow_root</span> |
| 2862 | +</span></span><span style=display:flex><span><span style=color:#000>shadow_content</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>shadow_root</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>find_element</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>css</span><span style=color:#000;font-weight:700>:</span> <span style=color:#4e9a06>'#shadow_content'</span><span style=color:#000;font-weight:700>)</span></span></span></code></pre></div></div><div class="tab-body tab-pane fade" id=tabs-04-05 role=tabpanel aria-labelled-by=tabs-04-05-tab tabindex=4><p><a href=/documentation/about/contributing/#creating-examples><span class=selenium-badge-code data-bs-toggle=tooltip data-bs-placement=right title="This code example is missing. Examples are added to the examples directory; click for details in the contribution guide">Add Example</span></a></p></div><div class="tab-body tab-pane fade" id=tabs-04-06 role=tabpanel aria-labelled-by=tabs-04-06-tab tabindex=4><p><a href=/documentation/about/contributing/#creating-examples><span class=selenium-badge-code data-bs-toggle=tooltip data-bs-placement=right title="This code example is missing. Examples are added to the examples directory; click for details in the contribution guide">Add Example</span></a></p></div></div><h3 id=optimized-locator>Optimized locator</h3><p>A nested lookup might not be the most effective location strategy since it requires two |
2861 | 2863 | separate commands to be issued to the browser.</p><p>To improve the performance slightly, we can use either CSS or XPath to find this element in a single command.
|
2862 | 2864 | See the <a href=https://www.selenium.dev/documentation/test_practices/encouraged/locators/>Locator strategy suggestions</a> in our
|
2863 | 2865 | <a href=https://www.selenium.dev/documentation/test_practices/encouraged/>Encouraged test practices</a> section.</p><p>For this example, we’ll use a CSS Selector:</p><p><a href=/documentation/about/contributing/#moving-examples><span class=selenium-badge-code data-bs-toggle=tooltip data-bs-placement=right title="One or more of these examples need to be implemented in the examples directory; click for details in the contribution guide">Move Code</span></a></p><ul class="nav nav-tabs" id=tabs-7 role=tablist><li class=nav-item><button class="nav-link active" id=tabs-07-01-tab data-bs-toggle=tab data-bs-target=#tabs-07-01 role=tab data-td-tp-persist=java aria-controls=tabs-07-01 aria-selected=true>
|
|
13969 | 13971 | <label><a href=https://github.com/jarib>@jarib</a></label>
|
13970 | 13972 | <span class=contributions>1299 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/5992658?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
13971 | 13973 | <label><a href=https://github.com/diemol>@diemol</a></label>
|
13972 |
| -<span class=contributions>1237 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/128518?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
| 13974 | +<span class=contributions>1240 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/128518?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
13973 | 13975 | <label><a href=https://github.com/AutomatedTester>@AutomatedTester</a></label>
|
13974 | 13976 | <span class=contributions>1223 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/96150?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
13975 | 13977 | <label><a href=https://github.com/dfabulich>@dfabulich</a></label>
|
|
14249 | 14251 | <label><a href=https://github.com/diemol>@diemol</a></label>
|
14250 | 14252 | <span class=contributions>538 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/23253546?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
14251 | 14253 | <label><a href=https://github.com/VietND96>@VietND96</a></label>
|
14252 |
| -<span class=contributions>222 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/3331063?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
| 14254 | +<span class=contributions>223 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/3331063?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
14253 | 14255 | <label><a href=https://github.com/selenium-ci>@selenium-ci</a></label>
|
14254 | 14256 | <span class=contributions>154 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/2972876?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
14255 | 14257 | <label><a href=https://github.com/ddavison>@ddavison</a></label>
|
|
14487 | 14489 | <label><a href=https://github.com/luisfcorreia>@luisfcorreia</a></label>
|
14488 | 14490 | <span class=contributions>15 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/69980130?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
14489 | 14491 | <label><a href=https://github.com/shbenzer>@shbenzer</a></label>
|
14490 |
| -<span class=contributions>13 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/in/15368?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
| 14492 | +<span class=contributions>14 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/in/15368?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle> |
14491 | 14493 | <label><a href=https://github.com/apps/github-actions>@github-actions[bot]</a></label>
|
14492 | 14494 | <span class=contributions>13 commits</span></div><div style=padding:10px><img src="https://avatars.githubusercontent.com/u/28229?v=4" class=inline width=100 height=100 style=height:100px;height:100px;margin-bottom:.25em;vertical-align:middle>
|
14493 | 14495 | <label><a href=https://github.com/shs96c>@shs96c</a></label>
|
|
0 commit comments