No response to click() or sendKeys() in automation script

Premise: Exclude the case of xpath reference error.

 

Problem Description

The click() method and the sendKeys() method in the automation script report an error and return the exception InvocationTargetException.

 

root cause

1) There are two tab pages, and the element to be selected exists in one of the tab pages

  

 

2) There are two forms, and the element to be selected exists in one of them.

  

 

 

 

Solution

Sometimes adding a dot in front of the xpath solves the problem, but sometimes it doesn't. It's better to do it in two steps:

a. Start from the current form or tab

  

1 public class subTabSendEnq {
2     final static String from = "/html/body/div[7]/div/div[2]"; //当前form的xpath
3     public static void input(String xpath, String input) {
4         WebElement s = AntBrowser.getBrowser().getElementFrom(AntBrowser.getBrowser().getElement(from), xpath);
5         s.sendKeys(input);
6     }
7 }

 

b. Add a dot in front of the xpath of the element to be positioned

 

1 subTabSendEnq.input(".//*[@id=\"fullname\"]", "abc"); //xpath前面加点

 

Guess you like

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