我遇到了一个问题,我们目前的移动项目,我们的点击不会与我们的设备页面上的保存按钮交互。这是到目前为止我们遇到的唯一一种情况。我尝试了各种XPath/定位器,包括将坐标放入XPath本身,但没有成功。此外,我注意到Clickable被设置为False,因此我还尝试了保存文本上方的属性,该属性被设置为Clickable True,但在那里也没有任何用处。任何想法都将受到欢迎!对于透视图,我需要能够单击保存按钮。当它运行时,它说它点击并尝试我们的验证,但模拟器上实际上没有发生任何事情。
POM:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId></groupId>
<artifactId>framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<testng.files.location>src/TestSuites/</testng.files.location>
<testng.file>testng.xml</testng.file>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<gridUrl>http://selenium-hub-1.qa.automation.vpc:4444/wd/hub</gridUrl>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${SuiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-to-slf4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.19.0</version>
</dependency>
</dependencies>
</project>
方法:
/**
* Registers a real lock from locations screen
*
* @throws InterruptedException
*/
public void addLock(String serialNumber, String model, String lockName) throws InterruptedException{
logg.info("Adding a device");
withAction.mobileClick(btnAddLock);
logg.info("Add Lock button is clicked");
logg.info("Clicking Scan QR Code button");
withAction.mobileClick(btnScanQRCode);
logg.info("Sending a serial number into the enter serial number manually field");
logg.info("Clicking Enter Serial Number Manually button");
withAction.mobileClick(btnEnterSNManually);
logg.info("Validating Enter serial number is displayed");
withAssert.mobileStringExists(txtEnterSN, "Enter serial number");
withAction.sendText(btnEnterSN, serialNumber);
logg.info("Clicking a model tile");
WebElement element = appiumDriver.findElement(By.xpath("//*[@text='" + model + "']"));
withAction.mobileClick(element);
logg.info("Clicking continue button");
withAction.mobileClick(btnContinue);
logg.info("Validating the next screen that is showing You are almost done! text");
withAssert.mobileStringExists(txtAlmostDone, "You are almost done!");
logg.info("Sending a name to a lock");
withAction.sendText(btnLockName, lockName);
withAction.mobileBack();
logg.info("Validating save button");
withAssert.mobileStringExists(txtSave, "Save");
Thread.sleep(3000);
logg.info("Clicking save lock button");
withAction.mobileClick(btnSaveLock); //this is where it needs to click
logg.info("Validating success message");
withAssert.mobileStringExists(txtSuccess, "Success!");
logg.info("Clicking next button");
withAction.mobileClick(btnNext);
logg.info("Clicking done button");
withAction.mobileClick(btnDone);
logg.info("Validating Lock Setup Not Finished message");
withAssert.mobileStringExists(txtSuccess, "Lock Setup Not Finished");
logg.info("Clicking I'll connect my lock later button");
withAction.mobileClick(btnConnectLater);
}
MobileClick方法
/**
* clicks an element
*
* @param element
*/
public void mobileClick(WebElement element) {
logg.info("Clicking an element by xpath");
WebDriverWait wait = new WebDriverWait(appiumDriver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.elementToBeClickable(element)).click();
}
1条答案
按热度按时间iezvtpos1#
尝试对元素执行
tap
操作,而不是常规的click
。通常情况下,这应该会点击元素。