Appium+java can't find the element and report an error that is different from the web version of selenium solution

=

The web version of selenium, can't find the element, returns null (I made a mistake before, and I ran the program again, and it also reported an error.).

I think it's very reasonable, and it's up to the developer to decide how to handle it. This situation is especially used in many different combinations, and it is necessary to judge which element type is element type by null.

 

But when it comes to Appium, an error is reported when the element is not found. I am dizzy.

Do you want me to catch it? This leads to a lot of ugly code.

Checked the source code, did you deliberately handle it like this,,, bird. . .

=

Solution:

If you want this element not to report an error when it is not found, just return null, and you can encapsulate the code.

It’s easy to deal with, is it a good idea to encapsulate a proxy!

    public static WebElement findElement (WebElement driver, By by) {
        return find(driver, by);
    }

    public static WebElement find(WebElement driver, By by){
        WebElement webElement = null;
        try {
            webElement = driver.findElement (by);
        } catch (Exception e){
//sth
        }
        return webElement;
    }

 

 

 

=

=

=

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326194283&siteId=291194637