/** * Get page source as String * * @return page source */ @PublicAtsApi public String getPageSource() { return this.appiumDriver.getPageSource(); }
public static String getPageSource(int second){ log.info("======================================================getPageSource"); if(second > 0){ sleep(second); } String xml=""; try { //在有特殊字符时 如&# DocumentBuilder.parse 会抛异常 xml = driver.getPageSource().replace("&#", ""); if (Util.isWin()) { xml = xml.replace("UTF-8", "gbk"); } if(ConfigUtil.isShowDomXML()) { log.info("\n\n\n\n\n" + xml + "\n\n\n\n\n"); } }catch (Exception e){ e.printStackTrace(); log.error("Fail to getPageSource!"); } return xml; }
public void gameCenterLogin() throws Exception { if (driver.getPageSource().contains("Sign in")) { log("Google Plus sign in shown..."); log(driver.getPageSource()); takeScreenshot("google_plus_sign_in_shown"); while (driver.getPageSource().contains("Sign in")) if (automationName.equalsIgnoreCase("selendroid")) { driver.findElement(By.xpath("//LinearLayout/Button[@text='Sign in']")).click(); } else if (platform.equals(PlatformType.ANDROID)) { driver.findElement(By.xpath("//android.widget.Button[@text='Sign in']")).click(); } else { //we are on ios driver.findElementByAccessibilityId("Sign In").click(); } takeScreenshot("after_clicking_sign_in"); } }
public void cancelGameCenterLogin() throws Exception { log("Check to see if Google Plus Sign in needs to be cancelled.."); if (driver.getPageSource().contains("Choose an account")) { if (automationName.equalsIgnoreCase("selendroid")) { driver.findElement(By.xpath("//LinearLayout/Button[@text='Cancel']")).click(); } else if (platform.equals(PlatformType.ANDROID)) { driver.findElement(By.xpath("//android.widget.Button[@text='Cancel']")).click(); } else { //we are on ios driver.findElementByAccessibilityId("Cancel").click(); } } if (automationName.equalsIgnoreCase("selendroid")) { ImageRecognitionSettings settings = new ImageRecognitionSettings(); settings.setRetries(1); while (findImageOnScreen("native_sign_in_button").isFound()) { tapImageOnScreen("native_sign_in_button", 0.75, 0.5, settings); } } else { if (driver.getPageSource().contains("SIGN IN") || (driver.getPageSource().contains("Sign in")) || (driver.getPageSource().contains("Sign In"))) { log("Google Plus sign in shown..."); takeScreenshot("google_plus_sign_in_shown"); driver.findElement(By.xpath("//android.widget.Button[@text='Cancel']")).click(); takeScreenshot("after_cancel_sign_in"); driver.findElement(By.xpath("//android.widget.Button[@text='Cancel']")).click(); takeScreenshot("after_second_cancel_sign_in"); } } }