0

我使用 python 在 Selenium appium 中开发自动测试。我需要滚动项目列表,但我不知道该怎么做。我尝试:

scrollLayout = android.driver.find_elements_by_class_name("android.widget.RelativeLayout")
params = {"element": scrollLayout[0].id, "text": SEARCH_STRING}
self.android.driver.execute_script("mobile: scrollTo", params)

但是,它不起作用。我该做什么?

4

2 回答 2

4
WebElement list = driver.findElement(By.id("id of your list"));

     HashMap<String, String> scrollObject = new HashMap<String, String>();
     scrollObject.put("text", "name to search");
     scrollObject.put("element",( (RemoteWebElement) list).getId());
     driver.executeScript("mobile: scrollTo", scrollObject);
     if(scrollObject.containsValue("string to search"))
     {
        System.out.println("Found");
        List<WebElement> list_user = list.findElements(By.id("id of the text view"));
        for (WebElement component : list_user) {
           System.out.println(component.getText());
           if (component.getText().contains("string to search")) {
                component.click();
                break;
            } else {
                System.out.println("Not equal");
            }
     }
     }
     else
     {
         System.out.println("Not Found");
     }
于 2014-11-21T10:52:46.200 回答
1

使用下面的代码它将起作用。这是java代码将它相应地更改为python

            WebElement element = driver.findElement(By.id("android:id/select_dialog_listview"));
            HashMap<String, String> scrollObject = new HashMap<String, String>();
            scrollObject.put("text", "The text name you need to scroll to");
            scrollObject.put("element",( (RemoteWebElement) element).getId());
            driver.executeScript("mobile: scrollTo", scrollObject);
于 2014-09-07T17:47:10.520 回答