Dry goods sorting, Selenium automated testing common abnormal problems + solutions (detailed)


foreword

Exception 1: Stale Element Reference Exception

Literal translation exception
Stale Element Reference Exception: stale element reference exception

First of all, under what circumstances will this exception occur
? Simply put, the page element has expired and the element cannot be referenced.

Common reasons for this exception
The element has been deleted entirely: The element has been deleted [more common]
The element is no longer attached to the DOM: The element is no longer attached to the DOM

The element has been removed
Analyze why
The most common reasons for this: Refresh the page the element resides on, or the user navigates to another page

Another cause: The JS library removes an element and replaces it with the same ID or attribute

Workaround:
Find the element again

The element is no longer attached to the DOM.
Analyze the reason
. It may be that the element that is no longer attached to the DOM tree is guided (for example, document.documentElement)

Solution:
still find the element again

The situation encountered:
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document [second case]

Under what circumstances do you encounter this problem?
For element hover, the method of calling Webdriver.ActionChains(driver).move_to_element(element).perform()

How to solve?
Catch the exception, reposition the element, and rehover

D1

If this can't solve your problem, you can try to click the element directly (of course, the premise is that clicking the element will not trigger any other interaction, so that click can be used to replace hover)

Exception 2: No Such Element Exception

Literal translation exception
No Such Element Exception: There is no such element exception

Under what circumstances will this exception occur
? The element does not exist, and cannot be located
. The element exists, but there is a problem with the positioning expression, and the element cannot be located. The
page has been loaded for too long, and the element has not been loaded, so the positioning failed

How to solve this problem
Cause 1: The element exists
Determine whether the element you are looking for exists on the page

Reason 2: There is a problem with the positioning expression.
First, make sure whether the element you want to find exists. If it exists, check whether there is a problem with the positioning expression.
F12 in the browser, enter elements, ctrl+f, and paste the positioning expression to see if it is corresponding elements can be found

Reason 3: The page loads too long.
Use explicit waiting or implicit waiting, and then locate the element after the element is successfully loaded.

The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Take the first step and chase your dreams. Only by working hard can we achieve extraordinary results. Persevere and keep the faith. Adversity is nothing but tempering, and struggle is the foundation of life. Shine youth, pursue brilliance. Success lies in continuous effort.

Every day, people are struggling silently, not for anything else, just to make themselves better. No matter how difficult it is, as long as you keep working hard, success is not far away. Believe in your own potential, go forward bravely, and create your own brilliance!

Only by doing your best can you reach the other side of success; only by persevering can you realize your ideals; only by working hard can you surpass your limits. Believe in yourself, go forward bravely, and you will be able to create your own brilliant life!

Guess you like

Origin blog.csdn.net/csdnchengxi/article/details/131578695