Solution to the failure of obtaining new page elements based on Selenium
When we use selenium to realize simulated Login, after obtaining the login button element, we can directly call its click () method to realize login jump, and the webdriver also points to
There is no problem with the current page, but it should be noted that the page loading speed is generally less than the program running speed. Therefore, before obtaining the elements of the logged in page, you can use the util method of webdriverwait or directly through thread Sleep() lets the program sleep for a while (not recommended).
However, Bo's main point is that if we click the ordinary hyperlink to enter the new page, we can't get the new page elements through the above method, because the webdriver still points to the previous page,
Solution: first obtain all handles of the window, then traverse the handle collection until the existing handle is different from the current handle of the current window, and turn the previous webdriver to the page pointed to by the new handle.
The code is as follows:
The above solution to the failure of obtaining new page elements based on selenium is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.