【问题标题】:Error when trying to swipe to org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen尝试滑动到 org.openqa.selenium.remote.RemoteWebDriver 时出错,无法转换为 org.openqa.selenium.interactions.HasTouchScreen
【发布时间】:2020-02-07 12:22:07
【问题描述】:

我试图在应用程序内滑动,它给了我以下错误 org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

请找到我的代码详细信息。 这是我的主要课程

public class Yf {

	WebDriver driver;
	// String path = System.getProperty("user.dir");

	WebDriverWait wait;

	DesiredCapabilities cap = new DesiredCapabilities();
	Swipe swipe = new Swipe(driver);

	@BeforeTest
	public void initConfig() {

		cap.setCapability("deviceName", "R58M439LBRY");
		cap.setCapability("platformName", "Android");
		// cap.setCapability(CapabilityType.BROWSER_NAME, "Android");
		cap.setCapability(CapabilityType.VERSION, "9");
		cap.setCapability("appPackage", "com.yellowfinbi.android");
		cap.setCapability("appActivity", "md5a479f257bdebd299ec30f02ebca2a5d0.LaunchActivity");

	}

	@Test
	public void Login() throws MalformedURLException, InterruptedException {
		RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
		WebElement SignInButton = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Login')]"));
		SignInButton.click();
		Thread.sleep(2000);
		WebElement ServerURL = driver
				.findElement(By.xpath("//android.widget.EditText[contains(@text,'Server URL (or address)')]"));
		ServerURL.sendKeys("https://chololo.yellowfin.bi/");
		Thread.sleep(2000);
		WebElement UserName = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Username')]"));
		UserName.sendKeys("bobby.chodagam@yellowfin.bi");
		Thread.sleep(2000);
		WebElement PassWord = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Password')]"));
		PassWord.sendKeys("Sai79baba");
		Thread.sleep(2000);
		WebElement Login = driver.findElement(By.xpath("//android.widget.TextView[contains(@index,'8')]"));
		Login.click();
		Thread.sleep(15000);
		swipe.Scroll(driver, DIRECTION.LEFT, 1000);

	}

}

请在下方找到刷卡方法代码

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.Augmenter;

public class Swipe {

	WebDriver driver;

	public Swipe(WebDriver driver) {
		this.driver = driver;
	}

	public enum DIRECTION {
		DOWN, UP, LEFT, RIGHT;
	}

	public void Scroll(WebDriver driver, DIRECTION direction, long duration) {
		Dimension size = driver.manage().window().getSize();
		TouchActions Action = new TouchActions(driver);

		int startX = 0;
		int endX = 0;
		int startY = 0;
		int endY = 0;

		switch (direction) {
		case RIGHT:
			startY = (int) (size.height / 2);
			startX = (int) (size.width * 0.90);
			endX = (int) (size.width * 0.05);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case LEFT:
			startY = (int) (size.height / 2);
			startX = (int) (size.width * 0.05);
			endX = (int) (size.width * 0.90);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case UP:
			endY = (int) (size.height * 0.70);
			startY = (int) (size.height * 0.30);
			startX = (size.width / 2);
			Action.scroll(startX, startY).move(endX, startY).release().perform();
			break;

		case DOWN:
			startY = (int) (size.height * 0.70);
			endY = (int) (size.height * 0.30);
			startX = (size.width / 2);
			Action.scroll(startX, startY).move(startX, endY).release().perform();
			break;

		}
	}

}

请让我知道我做错了什么。这也是我试图向左滑动的应用程序的屏幕截图。谢谢

【问题讨论】:

    标签: appium appium-android


    【解决方案1】:

    我通过如下声明解决了这个问题

    AppiumDriver<MobileElement> driver; and initialising as 
    driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    

    这是最终代码

    mport org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;
    
    import com.yellowfin.mobile.Swipe;
    import com.yellowfin.mobile.Swipe.DIRECTION;
    
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.MobileElement;
    import io.appium.java_client.android.AndroidDriver;
    
    public class Yf {
    
    	AppiumDriver<MobileElement> driver;
    	// String path = System.getProperty("user.dir");
    
    	WebDriverWait wait;
    	Swipe swipe;
    	DesiredCapabilities cap = new DesiredCapabilities();
    
    	@BeforeTest
    	public void initConfig() throws MalformedURLException {
    
    		cap.setCapability("deviceName", "R58M439LBRY");
    		cap.setCapability("platformName", "Android");
    		// cap.setCapability(CapabilityType.BROWSER_NAME, "Android");
    		cap.setCapability(CapabilityType.VERSION, "9");
    		cap.setCapability("appPackage", "com.yellowfinbi.android");
    		cap.setCapability("appActivity", "md5a479f257bdebd299ec30f02ebca2a5d0.LaunchActivity");
    		driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    		swipe = new Swipe(driver);
    	}
    
    	@Test
    	public void Login() throws InterruptedException {
    
    		WebElement SignInButton = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Login')]"));
    		SignInButton.click();
    		Thread.sleep(2000);
    		WebElement ServerURL = driver
    				.findElement(By.xpath("//android.widget.EditText[contains(@text,'Server URL (or address)')]"));
    		ServerURL.sendKeys("https://chololo.yellowfin.bi/");
    		Thread.sleep(2000);
    		WebElement UserName = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Username')]"));
    		UserName.sendKeys("bobby.chodagam@yellowfin.bi");
    		Thread.sleep(2000);
    		WebElement PassWord = driver.findElement(By.xpath("//android.widget.EditText[contains(@text,'Password')]"));
    		PassWord.sendKeys("Sai79baba");
    		Thread.sleep(2000);
    		WebElement Login = driver.findElement(By.xpath("//android.widget.TextView[contains(@index,'8')]"));
    		Login.click();
    		Thread.sleep(15000);
    		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
    		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
    		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
    		swipe.Scroll(driver, DIRECTION.RIGHT, 10);
    		
    	}
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      相关资源
      最近更新 更多