|
8816 | 8816 | 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>
|
8817 | 8817 | for ways get assistance.</p></li><li><p>If you think you’ve found a problem with Selenium code, go ahead and file a
|
8818 | 8818 | <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>
|
8819 |
| -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=invalid-selector-exception>Invalid Selector Exception</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=no-such-element-exception>No Such Element Exception</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=stale-element-reference-exception>Stale Element Reference Exception</h2><p>An element goes stale when it was previously located, but can not be currently accessed. |
| 8819 | +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. |
8820 | 8820 | Elements do not get relocated automatically; the driver creates a reference ID for the element and
|
8821 | 8821 | has a particular place it expects to find it in the DOM. If it can not find the element
|
8822 | 8822 | 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
|
|
8848 | 8848 | A great way is to use <code>ExpectedCondition.ToBeClickable()</code> with <code>WebDriverWait</code> to wait until the right moment.</p><p><strong>Scroll the Element into View</strong></p><p>In instances where the element is out of view, but Selenium still registers the element as visible
|
8849 | 8849 | (e.g. navbars overlapping a section at the top of your screen), you can use the <code>WebDriver.executeScript()</code>
|
8850 | 8850 | method to execute a javascript function to scroll (e.g. <code>WebDriver.executeScript('window.scrollBy(0,-250)')</code>)
|
8851 |
| -or you can utilize the Actions class with <code>Actions.moveToElement(element)</code>.</p><h2 id=invalid-sessionid-exception>Invalid SessionId Exception</h2><p>Sometimes the session you’re trying to access is different than what’s currently available</p><h3 id=likely-cause-4>Likely Cause</h3><p>This usually occurs when the session has been deleted (e.g. <code>driver.quit()</code>) or if the session has changed, |
| 8851 | +or you can utilize the Actions class with <code>Actions.moveToElement(element)</code>.</p><h2 id=invalidsessionidexception>InvalidSessionIdException</h2><p>Sometimes the session you’re trying to access is different than what’s currently available</p><h3 id=likely-cause-4>Likely Cause</h3><p>This usually occurs when the session has been deleted (e.g. <code>driver.quit()</code>) or if the session has changed, |
8852 | 8852 | like when the last tab/browser has closed (e.g. <code>driver.close()</code>)</p><h3 id=possible-solutions-4>Possible Solutions</h3><p>Check your script for instances of <code>driver.close()</code> and <code>driver.quit()</code>, and any other possible causes
|
8853 | 8853 | of closed tabs/browsers. It could be that you are locating an element before you should/can.</p></div><div class=td-content style=page-break-before:always><h1 id=pg-5a7d28a8d143d2eaa2a6727d561e2164>2.10.1.1 - Unable to Locate Driver Error</h1><div class=lead>Troubleshooting missing path to driver executable.</div><p>Historically, this is the most common error beginning Selenium users get
|
8854 | 8854 | when trying to run code for the first time:</p><ul class="nav nav-tabs" id=tabs-0 role=tablist><li class=nav-item><button class="nav-link active" id=tabs-00-00-tab data-bs-toggle=tab data-bs-target=#tabs-00-00 role=tab data-td-tp-persist=java aria-controls=tabs-00-00 aria-selected=true>
|
|
0 commit comments