|
178 | 178 | performing their operations in entirely different ways
|
179 | 179 | but which frequently look the same while doing so.
|
180 | 180 | Even though the text is rendered in the same fonts,
|
181 |
| -the images are displayed in the same place |
182 |
| -, and the links take you to the same destination. |
| 181 | +the images are displayed in the same place, |
| 182 | +and the links take you to the same destination. |
183 | 183 | What is happening underneath is as different as night and day.
|
184 | 184 | Selenium “abstracts” these differences,
|
185 | 185 | hiding their details and intricacies from the person writing the code.
|
|
213 | 213 | and build a strong community
|
214 | 214 | so that the project can continue to keep up with emerging technologies
|
215 | 215 | and remain a dominant platform for functional test automation.</p></div><div class=td-content style=page-break-before:always><h1 id=pg-03fac682a3f8ce461fb3631d7a8c09cf>2 - WebDriver</h1><div class=lead>WebDriver drives a browser natively; learn more about it.</div><p>WebDriver drives a browser natively, as a user would, either locally
|
216 |
| -or on a remote machine using the Selenium server, |
217 |
| -marks a leap forward in terms of browser automation.</p><p>Selenium WebDriver refers to both the language bindings |
| 216 | +or on a remote machine using the Selenium server. |
| 217 | +It marks a leap forward in terms of browser automation.</p><p>Selenium WebDriver refers to both the language bindings |
218 | 218 | and the implementations of the individual browser controlling code.
|
219 | 219 | This is commonly referred to as just <em>WebDriver</em>.</p><p>Selenium WebDriver is a <a href=https://www.w3.org/TR/webdriver1/>W3C Recommendation</a></p><ul><li><p>WebDriver is designed as a simple
|
220 | 220 | and more concise programming interface.</p></li><li><p>WebDriver is a compact object-oriented API.</p></li><li><p>It drives the browser effectively.</p></li></ul></div><div class=td-content style=page-break-before:always><h1 id=pg-83a05f84a53d59f39c7a07b577b25ad1>2.1 - Getting started</h1><div class=lead>If you are new to Selenium, we have a few resources that can help you get up to speed right away.</div><p>Selenium supports automation of all the major browsers in the market
|
|
8685 | 8685 | </span></span><span style=display:flex><span>Thread safety error; this instance of WebDriver was constructed
|
8686 | 8686 | </span></span><span style=display:flex><span>on thread main (id 1)and is being accessed by thread Thread-1 (id 24)
|
8687 | 8687 | </span></span><span style=display:flex><span>This is not permitted and *will* cause undefined behaviour
|
8688 |
| -</span></span></code></pre></div><p>As seen in the example:</p><ul><li><code>protectedDriver</code> Will be created in Main thread</li><li>We use Java <code>Runnable</code> to spin up a new process and a new <code>Thread</code> to run the process</li><li>Both <code>Thread</code> will clash because the Main Thread does not have <code>protectedDriver</code> in it’s memory.</li><li><code>ThreadGuard.protect</code> will throw an exception.</li></ul><h4 id=note>Note:</h4><p>This does not replace the need for using <code>ThreadLocal</code> to manage drivers when running parallel.</p></div><div class=td-content style=page-break-before:always><h1 id=pg-f6283427de39b51ad43d27f5c63829dd>2.10 - Troubleshooting Assistance</h1><div class=lead>How to get manage WebDriver problems.</div><p>It is not always obvious the root cause of errors in Selenium.</p><ol><li><p>The most common Selenium-related error is a result of poor synchronization. |
| 8688 | +</span></span></code></pre></div><p>As seen in the example:</p><ul><li><code>protectedDriver</code> Will be created in Main thread</li><li>We use Java <code>Runnable</code> to spin up a new process and a new <code>Thread</code> to run the process</li><li>Both <code>Thread</code> will clash because the Main Thread does not have <code>protectedDriver</code> in it’s memory.</li><li><code>ThreadGuard.protect</code> will throw an exception.</li></ul><h4 id=note>Note:</h4><p>This does not replace the need for using <code>ThreadLocal</code> to manage drivers when running parallel.</p></div><div class=td-content style=page-break-before:always><h1 id=pg-f6283427de39b51ad43d27f5c63829dd>2.10 - Troubleshooting Assistance</h1><div class=lead>How to solve WebDriver problems.</div><p>It is not always obvious the root cause of errors in Selenium.</p><ol><li><p>The most common Selenium-related error is a result of poor synchronization. |
8689 | 8689 | Read about <a href=https://www.selenium.dev/documentation/webdriver/waits/>Waiting Strategies</a>. If you aren’t sure if it
|
8690 | 8690 | is a synchronization strategy you can try <em>temporarily</em> hard coding a large sleep
|
8691 | 8691 | where you see the issue, and you’ll know if adding an explicit wait can help.</p></li><li><p>Note that many errors that get reported to the project are actually caused by
|
8692 | 8692 | issues in the underlying drivers that Selenium sends the commands to. You can rule
|
8693 | 8693 | out a driver problem by executing the command in multiple <a href=https://www.selenium.dev/documentation/webdriver/browsers/>browsers</a>.</p></li><li><p>If you have questions about how to do things, check out the <a href=/support/>Support options</a>
|
8694 | 8694 | for ways get assistance.</p></li><li><p>If you think you’ve found a problem with Selenium code, go ahead and file a
|
8695 | 8695 | <a href="https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+">Bug Report</a>
|
8696 |
| -on GitHub.</p></li></ol></div><div class=td-content style=page-break-before:always><h1 id=pg-9106a7ac709cadefdb6e4b92e9e3ceaf>2.10.1 - Understanding Common Errors</h1><div class=lead>How to get deal with various problems in your Selenium code.</div><h2 id=invalidselectorexception>InvalidSelectorException</h2><p>CSS and XPath Selectors are sometimes difficult to get correct.</p><h3 id=likely-cause>Likely Cause</h3><p>The CSS or XPath selector you are trying to use has invalid characters or an invalid query.</p><h3 id=possible-solutions>Possible Solutions</h3><p>Run your selector through a validator service:</p><ul><li><a href=http://csslint.net/>CSS Validator</a></li><li><a href=http://www.freeformatter.com/xpath-tester.html>xPath Validator</a></li></ul><p>Or use a browser extension to get a known good value:</p><ul><li><a href=https://selectorshub.com/selectorshub/>SelectorsHub</a></li></ul><h2 id=nosuchelementexception>NoSuchElementException</h2><p>The element can not be found at the exact moment you attempted to locate it.</p><h3 id=likely-cause-1>Likely Cause</h3><ul><li>You are looking for the element in the wrong place (perhaps a previous action was unsuccessful).</li><li>You are looking for the element at the wrong time (the element has not shown up in the DOM, yet)</li><li>The locator has changed since you wrote the code</li></ul><h3 id=possible-solutions-1>Possible Solutions</h3><ul><li>Make sure you are on the page you expect to be on, and that previous actions in your code completed correctly</li><li>Make sure you are using a proper <a href=https://www.selenium.dev/documentation/webdriver/waits/>Waiting Strategy</a></li><li>Update the locator with the browser’s devtools console or use a browser extension like:<ul><li><a href=https://selectorshub.com/selectorshub/>SelectorsHub</a></li></ul></li></ul><h2 id=staleelementreferenceexception>StaleElementReferenceException</h2><p>An element goes stale when it was previously located, but can not be currently accessed. |
| 8696 | +on GitHub.</p></li></ol></div><div class=td-content style=page-break-before:always><h1 id=pg-9106a7ac709cadefdb6e4b92e9e3ceaf>2.10.1 - Understanding Common Errors</h1><div class=lead>How to solve various problems in your Selenium code.</div><h2 id=invalidselectorexception>InvalidSelectorException</h2><p>CSS and XPath Selectors are sometimes difficult to get correct.</p><h3 id=likely-cause>Likely Cause</h3><p>The CSS or XPath selector you are trying to use has invalid characters or an invalid query.</p><h3 id=possible-solutions>Possible Solutions</h3><p>Run your selector through a validator service:</p><ul><li><a href=http://csslint.net/>CSS Validator</a></li><li><a href=http://www.freeformatter.com/xpath-tester.html>xPath Validator</a></li></ul><p>Or use a browser extension to get a known good value:</p><ul><li><a href=https://selectorshub.com/selectorshub/>SelectorsHub</a></li></ul><h2 id=nosuchelementexception>NoSuchElementException</h2><p>The element can not be found at the exact moment you attempted to locate it.</p><h3 id=likely-cause-1>Likely Cause</h3><ul><li>You are looking for the element in the wrong place (perhaps a previous action was unsuccessful).</li><li>You are looking for the element at the wrong time (the element has not shown up in the DOM, yet)</li><li>The locator has changed since you wrote the code</li></ul><h3 id=possible-solutions-1>Possible Solutions</h3><ul><li>Make sure you are on the page you expect to be on, and that previous actions in your code completed correctly</li><li>Make sure you are using a proper <a href=https://www.selenium.dev/documentation/webdriver/waits/>Waiting Strategy</a></li><li>Update the locator with the browser’s devtools console or use a browser extension like:<ul><li><a href=https://selectorshub.com/selectorshub/>SelectorsHub</a></li></ul></li></ul><h2 id=staleelementreferenceexception>StaleElementReferenceException</h2><p>An element goes stale when it was previously located, but can not be currently accessed. |
8697 | 8697 | Elements do not get relocated automatically; the driver creates a reference ID for the element and
|
8698 | 8698 | has a particular place it expects to find it in the DOM. If it can not find the element
|
8699 | 8699 | in the current DOM, any action using that element will result in this exception.</p><h3 id=likely-cause-2>Likely Cause</h3><p>This can happen when:</p><ul><li>You have refreshed the page, or the DOM of the page has dynamically changed.</li><li>You have navigated to a different page.</li><li>You have switched to another window or into or out of a frame or iframe.</li></ul><h3 id=possible-solutions-2>Possible Solutions</h3><p><strong>The DOM has changed</strong></p><p>When the page is refreshed or items on the page have moved around, there is still
|
|
0 commit comments