Element operation method in appium TIPS (Java)

Search for elements

Off-screen elements

It seems that it cannot be taken. You can't "scroll to this element" because you can't get it in the first place. I swiped properly when I did it, but I don't know the correct (stable) method.

dialog

I was able to get it with findElement type functions until a while ago, but now it looks like this

python


    appiumDriver.switchTo().alert().accept(); 
    //appiumDriver is an instance of AppiumDriver

retry

When displaying the screen with Webview or displaying the screen based on the information from the network, the loading may not be completed by the timeout. You can add weights normally, but if you try again several times, you can save some time. But usually you should think about why it's so heavy.

python



/*
 *A function that just squeezes the sleep exception
 */
  static public void sleep(int millis) {
    try {
      Thread.sleep(millis);
    } catch (Exception e) {
    //Since it is just a weight, the exception is to put out only the stack trace and squeeze it appropriately.
      e.printStackTrace();
    }
  }

  /**
   * try find element /retry/ times.
   * @param by
   * @param retry
   * @return
   */
  public WebElement findElementByXPathSometime(final String by, final int retry){
    int count;
    RuntimeException ex=null;
    WebElement elem;
    for(count = 1;count<=retry;count++) {
      try {
        logger.debug("try to get element : " + by.toString());
        //log4j logger
        elem = appiumDriver.findElementByXPath(by);
        //appiumDriver is an instance of AppiumDriver
        return elem;
      }catch(RuntimeException e) {
        ex = e;
        logger.debug("failed to get element");
        sleep(5000);
      }
    }

Click on an element

There is an element that WebElement # click () does not respond to. Maybe it doesn't respond to the elements in Webview, so do the following:

python


    WebElement element = findElementByXPathSometime(AppElements.SETTING,20);
    new TouchAction(appiumDriver).tap(element).perform();
    //appiumDriver is an instance of AppiumDriver

Text box

This was no longer possible. For some reason, I can't find the element with ʻAppiumDriver # findElementBy Hogehoge ()`.

python


    (new TouchAction(appiumDriver)).tap(123, 456).perform();
    //Forcibly tap the text box
    sleep(1000);
    appiumDriver.getKeyboard().pressKey("nyuuryokusitaimoziretu");

Note that ʻAppiumDriver # getKeyboard ()` fails because the soft keyboard does not appear when the hard keyboard is enabled in the iOS simulator. inconvenience.

Recommended Posts

Element operation method in appium TIPS (Java)
Automatic photo resizing method in Java
Call the super method in Java
Java tips, tips
Java method
java (method)
Java method
[Java] method
Java Tips
[Java] method
Call Java method from JavaScript executed in Java
Concurrency Method in Java with basic example
[Java] Collection and StringBuilder operation method comparison
[Java] Handling of JavaBeans in the method chain
Java code TIPS
Partization in Java
Java method call from RPG (method call in own class)
Changes in Java 11
Java8 method reference
How to get Class from Element in Java
Method name of method chain in Java Builder + α
java8 method reference
Pi in Java
[Java] split method
FizzBuzz in Java
[Java] Get KFunction from Method / Constructor in Java [Kotlin]
Include image in jar file with java static method
[Java] File system operation
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Play Framework2.5 (Java) Tips
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
JAVA DB connection method
NVL-ish guy in Java
Combine arrays in Java
Callable Interface in Java
Java learning 2 (learning calculation method)
Comments in Java source
Java learning memo (method)
Azure functions in java
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Format XML in Java
Studying Java 8 (see method)
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Java programming (class method)
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
Java8 Stream reduction operation
ASCII art in Java