|
83 | 83 | </span></span></code></pre></div><br><h3 id=add-to-projects-gemfile>Add to project’s gemfile</h3><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-Gemfile data-lang=Gemfile><span style=display:flex><span><span style=color:#000>gem</span> <span style=color:#4e9a06>'selenium-devtools'</span><span style=color:#000;font-weight:700>,</span> <span style=color:#4e9a06>'= 0.132.0'</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/ruby/Gemfile#L10 target=_blank><i class="fas fa-external-link-alt pl-2"></i>
|
84 | 84 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-00-04 role=tabpanel aria-labelled-by=tabs-00-04-tab tabindex=0><p>You can find the minimum required version of Node for any given version of Selenium in the
|
85 | 85 | <code>Node Support Policy</code> section on <a href=https://www.npmjs.com/package/selenium-webdriver>npmjs</a></p><p>Selenium is typically installed using npm.</p><h3 id=install-locally>Install locally</h3><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>npm install selenium-webdriver
|
86 |
| -</span></span></code></pre></div><br><h3 id=add-to-project>Add to project</h3><p>In your project’s <code>package.json</code>, add requirement to <code>dependencies</code>:</p><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-json data-lang=json><span style=display:flex><span> <span style=color:#4e9a06>"mocha"</span><span style=color:#a40000>:</span> <span style=color:#4e9a06>"11.0.1"</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/javascript/package.json#L14 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
| 86 | +</span></span></code></pre></div><br><h3 id=add-to-project>Add to project</h3><p>In your project’s <code>package.json</code>, add requirement to <code>dependencies</code>:</p><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-json data-lang=json><span style=display:flex><span> <span style=color:#4e9a06>"mocha"</span><span style=color:#a40000>:</span> <span style=color:#4e9a06>"11.1.0"</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/javascript/package.json#L14 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
87 | 87 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-00-05 role=tabpanel aria-labelled-by=tabs-00-05-tab tabindex=0>Use the Java bindings for Kotlin.</div></div><h2 id=next-step>Next Step</h2><p><a href=https://www.selenium.dev/documentation/webdriver/getting_started/first_script/>Create your first Selenium script</a></p></div><div class=td-content style=page-break-before:always><h1 id=pg-422333a0d0201faac798caa658508cf1>1.2 - Write your first Selenium script</h1><div class=lead>Step-by-step instructions for constructing a Selenium script</div><p>Once you have <a href=https://www.selenium.dev/documentation/webdriver/getting_started/install_library/>Selenium installed</a>,
|
88 | 88 | you’re ready to write Selenium code.</p><h2 id=eight-basic-components>Eight Basic Components</h2><p>Everything Selenium does is send the browser commands to do something or send requests for information.
|
89 | 89 | Most of what you’ll do with Selenium is a combination of these basic commands</p><p>Click on the link to “View full example on GitHub” to see the code in context.</p><h3 id=1-start-the-session>1. Start the session</h3><p>For more details on starting a session read our documentation on <a href=https://www.selenium.dev/documentation/webdriver/drivers/>driver sessions</a></p><ul class="nav nav-tabs" id=tabs-2 role=tablist><li class=nav-item><button class="nav-link active" id=tabs-02-00-tab data-bs-toggle=tab data-bs-target=#tabs-02-00 role=tab data-td-tp-persist=java aria-controls=tabs-02-00 aria-selected=true>
|
|
2471 | 2471 | </span></span></span><span style=display:flex><span><span style=color:#f8f8f8;text-decoration:underline> </span><span style=color:#000>wait</span><span style=color:#000;font-weight:700>.</span><span style=color:#c4a000>until</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>d</span><span style=color:#f8f8f8;text-decoration:underline> </span><span style=color:#ce5c00;font-weight:700>-></span><span style=color:#f8f8f8;text-decoration:underline> </span><span style=color:#000>revealed</span><span style=color:#000;font-weight:700>.</span><span style=color:#c4a000>isDisplayed</span><span style=color:#000;font-weight:700>());</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/java/src/test/java/dev/selenium/waits/WaitsTest.java#L67-L68 target=_blank><i class="fas fa-external-link-alt pl-2"></i>
|
2472 | 2472 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-04-01 role=tabpanel aria-labelled-by=tabs-04-01-tab tabindex=4><p>This example shows the condition being waited for as a <em>lambda</em>. Python also supports
|
2473 | 2473 | <a href=https://www.selenium.dev/documentation/webdriver/support_features/expected_conditions/>Expected Conditions</a></p><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-py data-lang=py><span style=display:flex><span> <span style=color:#000>wait</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>WebDriverWait</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>timeout</span><span style=color:#ce5c00;font-weight:700>=</span><span style=color:#0000cf;font-weight:700>2</span><span style=color:#000;font-weight:700>)</span>
|
2474 |
| -</span></span><span style=display:flex><span> <span style=color:#000>wait</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>until</span><span style=color:#000;font-weight:700>(</span><span style=color:#204a87;font-weight:700>lambda</span> <span style=color:#000>d</span> <span style=color:#000;font-weight:700>:</span> <span style=color:#000>revealed</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>is_displayed</span><span style=color:#000;font-weight:700>())</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/waits/test_waits.py#L41-L42 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
| 2474 | +</span></span><span style=display:flex><span> <span style=color:#000>wait</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>until</span><span style=color:#000;font-weight:700>(</span><span style=color:#204a87;font-weight:700>lambda</span> <span style=color:#000>_</span> <span style=color:#000;font-weight:700>:</span> <span style=color:#000>revealed</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>is_displayed</span><span style=color:#000;font-weight:700>())</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/waits/test_waits.py#L41-L42 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
2475 | 2475 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-04-02 role=tabpanel aria-labelled-by=tabs-04-02-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-cs data-lang=cs><span style=display:flex><span> <span style=color:#000>WebDriverWait</span> <span style=color:#000>wait</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#204a87;font-weight:700>new</span> <span style=color:#000>WebDriverWait</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>TimeSpan</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FromSeconds</span><span style=color:#000;font-weight:700>(</span><span style=color:#0000cf;font-weight:700>2</span><span style=color:#000;font-weight:700>));</span>
|
2476 | 2476 | </span></span><span style=display:flex><span> <span style=color:#000>wait</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>Until</span><span style=color:#000;font-weight:700>(</span><span style=color:#000>d</span> <span style=color:#000;font-weight:700>=></span> <span style=color:#000>revealed</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>Displayed</span><span style=color:#000;font-weight:700>);</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/dotnet/SeleniumDocs/Waits/WaitsTest.cs#L56-L57 target=_blank><i class="fas fa-external-link-alt pl-2"></i>
|
2477 | 2477 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body 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-rb data-lang=rb><span style=display:flex><span> <span style=color:#000>wait</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>Selenium</span><span style=color:#ce5c00;font-weight:700>::</span><span style=color:#000>WebDriver</span><span style=color:#ce5c00;font-weight:700>::</span><span style=color:#000>Wait</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>new</span>
|
|
2498 | 2498 | </span></span></span><span style=display:flex><span><span style=color:#f8f8f8;text-decoration:underline> </span><span style=color:#000;font-weight:700>});</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/java/src/test/java/dev/selenium/waits/WaitsTest.java#L82-L92 target=_blank><i class="fas fa-external-link-alt pl-2"></i>
|
2499 | 2499 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-05-01 role=tabpanel aria-labelled-by=tabs-05-01-tab tabindex=5><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-py data-lang=py><span style=display:flex><span> <span style=color:#000>errors</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000;font-weight:700>[</span><span style=color:#000>NoSuchElementException</span><span style=color:#000;font-weight:700>,</span> <span style=color:#000>ElementNotInteractableException</span><span style=color:#000;font-weight:700>]</span>
|
2500 | 2500 | </span></span><span style=display:flex><span> <span style=color:#000>wait</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#000>WebDriverWait</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>timeout</span><span style=color:#ce5c00;font-weight:700>=</span><span style=color:#0000cf;font-weight:700>2</span><span style=color:#000;font-weight:700>,</span> <span style=color:#000>poll_frequency</span><span style=color:#ce5c00;font-weight:700>=</span><span style=color:#0000cf;font-weight:700>.2</span><span style=color:#000;font-weight:700>,</span> <span style=color:#000>ignored_exceptions</span><span style=color:#ce5c00;font-weight:700>=</span><span style=color:#000>errors</span><span style=color:#000;font-weight:700>)</span>
|
2501 |
| -</span></span><span style=display:flex><span> <span style=color:#000>wait</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>until</span><span style=color:#000;font-weight:700>(</span><span style=color:#204a87;font-weight:700>lambda</span> <span style=color:#000>d</span> <span style=color:#000;font-weight:700>:</span> <span style=color:#000>revealed</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>send_keys</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>"Displayed"</span><span style=color:#000;font-weight:700>)</span> <span style=color:#204a87;font-weight:700>or</span> <span style=color:#204a87;font-weight:700>True</span><span style=color:#000;font-weight:700>)</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/waits/test_waits.py#L53-L55 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
| 2501 | +</span></span><span style=display:flex><span> <span style=color:#000>wait</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>until</span><span style=color:#000;font-weight:700>(</span><span style=color:#204a87;font-weight:700>lambda</span> <span style=color:#000>_</span> <span style=color:#000;font-weight:700>:</span> <span style=color:#000>revealed</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>send_keys</span><span style=color:#000;font-weight:700>(</span><span style=color:#4e9a06>"Displayed"</span><span style=color:#000;font-weight:700>)</span> <span style=color:#204a87;font-weight:700>or</span> <span style=color:#204a87;font-weight:700>True</span><span style=color:#000;font-weight:700>)</span></span></span></code></pre></div><div class="text-end pb-2"><a href=https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/tests/waits/test_waits.py#L53-L55 target=_blank><i class="fas fa-external-link-alt pl-2"></i> |
2502 | 2502 | <strong>View full example on GitHub</strong></a></div></div><div class="tab-body tab-pane fade" id=tabs-05-02 role=tabpanel aria-labelled-by=tabs-05-02-tab tabindex=5><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cs data-lang=cs><span style=display:flex><span> <span style=color:#000>WebDriverWait</span> <span style=color:#000>wait</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#204a87;font-weight:700>new</span> <span style=color:#000>WebDriverWait</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>TimeSpan</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FromSeconds</span><span style=color:#000;font-weight:700>(</span><span style=color:#0000cf;font-weight:700>2</span><span style=color:#000;font-weight:700>))</span>
|
2503 | 2503 | </span></span><span style=display:flex><span> <span style=color:#000;font-weight:700>{</span>
|
2504 | 2504 | </span></span><span style=display:flex><span> <span style=color:#000>PollingInterval</span> <span style=color:#000;font-weight:700>=</span> <span style=color:#000>TimeSpan</span><span style=color:#000;font-weight:700>.</span><span style=color:#000>FromMilliseconds</span><span style=color:#000;font-weight:700>(</span><span style=color:#0000cf;font-weight:700>300</span><span style=color:#000;font-weight:700>),</span>
|
|
0 commit comments