Android 自动测试中的滚动布局
我使用python在Selenium appium中开发了自动测试。 我需要滚动项目列表,但我不知道如何做。 我尝试: 但是,它不起作用。Android 自动测试中的滚动布局,android,python,selenium,appium,Android,Python,Selenium,Appium,我使用python在Selenium appium中开发了自动测试。 我需要滚动项目列表,但我不知道如何做。 我尝试: 但是,它不起作用。 我应该怎么做?使用下面的代码它会工作的。这是java代码,将其相应地更改为python WebElement element = driver.findElement(By.id("android:id/select_dialog_listview")); HashMap<String, String&g
我应该怎么做?使用下面的代码它会工作的。这是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);
WebElement=driver.findElement(By.id(“android:id/select\u dialog\u listview”);
HashMap scrollObject=新建HashMap();
scrollObject.put(“文本”,“需要滚动到的文本名称”);
scrollObject.put(“element”,((RemoteWebElement)element.getId());
executeScript(“mobile:scrollTo”,scrollObject);
使用下面的代码,它将起作用。这是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);
WebElement=driver.findElement(By.id(“android:id/select\u dialog\u listview”);
HashMap scrollObject=新建HashMap();
scrollObject.put(“文本”,“需要滚动到的文本名称”);
scrollObject.put(“element”,((RemoteWebElement)element.getId());
executeScript(“mobile:scrollTo”,scrollObject);
WebElement list=driver.findElement(By.id(“您列表的id”);
HashMap scrollObject=新建HashMap();
scrollObject.put(“文本”、“要搜索的名称”);
scrollObject.put(“元素”,((RemoteWebElement)list.getId());
executeScript(“mobile:scrollTo”,scrollObject);
if(scrollObject.containsValue(“要搜索的字符串”))
{
System.out.println(“找到”);
List\u user=List.findElements(By.id(“文本视图的id”);
for(WebElement组件:列表\用户){
System.out.println(component.getText());
if(component.getText()包含(“要搜索的字符串”)){
组件。单击();
打破
}否则{
System.out.println(“不相等”);
}
}
}
其他的
{
System.out.println(“未找到”);
}
WebElement list=driver.findElement(By.id(“您列表的id”);
HashMap scrollObject=新建HashMap();
scrollObject.put(“文本”、“要搜索的名称”);
scrollObject.put(“元素”,((RemoteWebElement)list.getId());
executeScript(“mobile:scrollTo”,scrollObject);
if(scrollObject.containsValue(“要搜索的字符串”))
{
System.out.println(“找到”);
List\u user=List.findElements(By.id(“文本视图的id”);
for(WebElement组件:列表\用户){
System.out.println(component.getText());
if(component.getText()包含(“要搜索的字符串”)){
组件。单击();
打破
}否则{
System.out.println(“不相等”);
}
}
}
其他的
{
System.out.println(“未找到”);
}
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");
}