In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
When running automation, you often encounter the problem that it takes time for the elements of the page to load, and this time is uncertain, but your execution has been going down step by step, if the actual page waiting time is too long so that a dom element has not come out, but your code directly uses this WebElement, then it will throw a NullPointer exception.
In order to solve this problem, especially RemoteWebDriver (where there are more uncertainties), we need to use the very advanced functions of WebDriverWait.
In short, the WebDriverWait is to wait until a certain condition is met and then move on.
Paste the sample code:
WebDriverWait wait = new WebDriverWait (getWebDriver (), 3); wait.until (new ExpectedCondition () {public Boolean apply (WebDriver webDriver) {return! justification.getAttribute ("class"). Contains ("x-form-invalid-field") })
What does this code do? it means that by default, webDriver waits for up to 3 seconds until the style of the WebElement element called justification on the page does not contain x-form-invalid-field.
Analysis:
What does this mean? Very simple, because every field on our page is validated by js form, if the element on this page is typed incorrectly, there will be a red box to prompt the user to enter illegally, and the style of this red box is x-form-invalid-field, so our role is to wait for the red box to disappear, and then proceed to the next step.
As shown below:
Because the WebElement of this justification is mandatory for the user, if the user does not enter it, there is a red box:
Then the style of the red box contains x-form-invalid-field, as shown below:
So it's pretty clear now that our goal is to make the red box disappear when we run automation testcase.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.