0

如何在 selenium webdriver 中使用 md-select 和 md-option 选择下拉菜单。

不支持选择类。

<md-select placeholder="Filter" class="filter-select md-no-underline ng-pristine ng-valid ng-empty ng-touched" ng-model="$ctrl.dummy" aria-label="Filters" tabindex="0" aria-disabled="false" role="listbox" aria-expanded="false" aria-multiselectable="false" id="select_80" aria-invalid="false" style=""><md-select-value class="md-select-value md-select-placeholder" id="select_value_label_70"><span>Filter</span><span class="md-select-icon" aria-hidden="true"></span></md-select-value><div class="md-select-menu-container" aria-hidden="true" role="presentation" id="select_container_81"><md-select-menu role="presentation" class="_md"><md-content class="_md">
            <!-- ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_93"><div class="md-text ng-binding">
                Pending
            </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_94"><div class="md-text ng-binding">
                Posted
            </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_95"><div class="md-text ng-binding">
                Checks &amp; eChecks
            </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_96"><div class="md-text ng-binding">
                Deposit
            </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_97"><div class="md-text ng-binding">
                Withdrawal
            </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters -->
        </md-content></md-select-menu></div></md-select>

4

2 回答 2

1

假设您Pending要从选项中进行选择。你可以这样做:

WebElement option = driver.findElement(By.id("select_option_93"));
option.click();
于 2018-03-22T03:58:32.793 回答
0

以下代码提供了来自 selenium 驱动程序的完美设备连接

    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import com.perfectomobile.selenium.api.IMobileDevice;
    import com.perfectomobile.selenium.api.IMobileDriver;
    import com.perfectomobile.selenium.api.IMobileWebDriver;
    import com.perfectomobile.selenium.params.analyze.text.MobileTextMatchMode;
    public class BofaApp_app extends PerfectoMobileBasicTest implements Runnable{

        /*
        *
        *   Class Name  : PerfectoMobileBasicTest
        *   Author      : Uzi Eilon <uzie@perfectomobile.com>
        *   Date        : Dec 6th 2013  
        *   
        *   Description :
        *   Mobile Native application test 
        *   The test open the BOFA app (on a real device) and looks for an ATM.
        *   This test contains IMobileWebDriver (extension to webdriver), which allows the to get native and visual objects on mobile app 
        * 
        */


        public BofaApp_app(IMobileDriver driver) {
            super(driver);
        }

        @Override
        public void execTest() {


            IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId);
            device.open();
            device.home();

            IMobileWebDriver webDriver = _driver.getDevice(_DeviceId).getVisualDriver();
            webDriver.findElement(By.linkText("Bofa")).click();

            IMobileWebDriver init = _driver.getDevice(_DeviceId).getVisualDriver();
            init.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            init.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
            init.findElement(By.linkText("Account")).click();   

            webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
             webDriver.findElement(By.linkText("Save this online"));
             webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
             webDriver.findElement(By.linkText("Locations")).click();
             webDriver.findElement(By.linkText("Find Bank of America ATMs"));
             IMobileWebDriver zip = _driver.getDevice(_DeviceId).getVisualDriver();
             zip.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
             zip.findElement(By.linkText("zip code")).click();
             sleep(2000);
             zip.findElement(By.linkText("zip code")).click();
             sleep(2000);
             webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
             webDriver.manageMobile().visualOptions().ocrOptions().setLevelsLow(120);
             webDriver.findElement(By.linkText("Code")).sendKeys("02459");

             zip.findElement(By.linkText("Done")).click();
             zip.findElement(By.linkText("Go")).click();
             webDriver.findElement(By.linkText("Newton MA"));


        } 
    }*
    public class Constants
    {
      /** Project Constants */
       public static final String REPORT_LIB = "C:\\Test\\";
       public static final String HTML_REPORT_NAME = "Total.html";
       public static final String PM_USER = "uzie@perfectomobile.com";

       public static final String PM_PASSWORD = "*************";
       public static final String PM_CLOUD = "prerelease.perfectomobile.com";
       }
    public interface ExecutionReporter {


        /*
        *
        *   Class Name  : ExecutionReporter
        *   Author      : Uzi Eilon <uzie@perfectomobile.com>
        *   Date        : Dec 6th 2013  
        *   
        *   Description :
        *   Reporter allows you to build an summary report which aggregate all the executions the results and the link for the specific test report 
        *   You can find an HTML reporter in this project
        *   
        */

        public void reportHeader (String title);

        public void addLine(String testName,String deviceID,String repID,boolean status);

        public void closeRep();

    }
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    /*
    *
    *   Class Name  : HTMLReporter
    *   Author      : Uzi Eilon <uzie@perfectomobile.com>
    *   Date        : Dec 6th 2013  
    *   
    *   Description :
    *   implements ExecutionReporter and create an HTML summary report 
    *   
    */
    public class HTMLReporter implements ExecutionReporter  {

        BufferedWriter _bw = null;
        public HTMLReporter (String title )
        {
            reportHeader(title);
        }

        public void reportHeader (String title)
        {
            String repName = Constants.REPORT_LIB+ Constants.HTML_REPORT_NAME;
            File f = new File (repName) ;
            try {
                _bw = new BufferedWriter(new FileWriter(f));
                DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                 Calendar cal = Calendar.getInstance();

                _bw.write("<p> Date  :"+dateFormat.format(cal.getTime())+" </p>");
                _bw.write("<p> Test Name: "+title+"</p>");
                _bw.write("<p>");
                _bw.write("<p>");
                _bw.write("<table border=\"1\">");

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        public void addLine(String testName,String deviceID,String repID,boolean status)
        {
            try {
                _bw.write("<tr>");
                _bw.write("<td>"+testName+"</td>");
                _bw.write("<td>"+deviceID+"</td>");
                _bw.write("<td> <a href=\""+repID+"\">Report</a></td>");

                _bw.write("<td>"+status+"</td>");
                _bw.write("</tr>");


            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        public void closeRep()
        {
            try {
                _bw.write("</table></p></body></html>");
                _bw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    import java.lang.reflect.Constructor;
    import com.perfectomobile.selenium.*;
    import com.perfectomobile.selenium.api.*;
    public class MobileTest {


        /*
        *
        *   Class Name  : MobileTest
        *   Author      : Uzi Eilon <uzie@perfectomobile.com>
        *   Date        : Dec 6th 2013  
        *   
        *   Description :
        *   Mobile Executer gets list of test and devices and execute it on the available devices 
        *   in this example the list arrive form array [] [] 
        *   The tests run on real devices in Perfecto Mobile cloud 
            */


        public static void main(String[] args) {
            System.out.println("Script started");
            String host = Constants.PM_CLOUD;
            String user = Constants.PM_USER;
            String password = Constants.PM_PASSWORD;


            String[] [] testcase ={
            //   {"PerfectoTestCheckFlight","3230D2D238BECF6D"},
            //  {"PerfectoTestCheckFlight","4A8203C8DBAB382EE6BB8021B825A736CA734484"},
                 {"BofaApp_app","4A8203C8DBAB382EE6BB8021B825A736CA734484"},
            //       {"usAirways","3230D2D238BECF6D"}

            };

            ExecutionReporter reporter = new HTMLReporter("Regression Test Tesults");
            try {
                for(int i =0; i < testcase.length; i++)
                  {
                    IMobileDriver driver = new MobileDriver(host, user, password);
                    String className = testcase[i][0];
                    String device  = testcase[i][1];

                    PerfectoMobileBasicTest test = null;
                    Constructor con = null;

                    try {
                         con = Class.forName(className).getConstructor(IMobileDriver.class);
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    try {
                         test = (PerfectoMobileBasicTest)con.newInstance(driver);
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }

                    //PerfectoMobileBasicTest test = new PerfectoTestCheckFlight(driver);
                    test.setDeviceID(device);
                    Thread t = new Thread(test);
                    t.start();
                    reporter.addLine(className,device,test.getRepName(),test.getStatus());
                    }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                reporter.closeRep();
            }
        }


    }
    import java.io.File;
    import java.io.InputStream;
    import com.perfectomobile.httpclient.MediaType;
    import com.perfectomobile.httpclient.utils.FileUtils;
    import com.perfectomobile.selenium.api.IMobileDriver;
    /*
    *
    *   Class Name  : PerfectoMobileBasicTest
    *   Author      : Uzi Eilon <uzie@perfectomobile.com>
    *   Date        : Dec 6th 2013  
    *   
    *   Description :
    Basic abstract perfecto mobile test - Each test need to extend this class and implement the actual test in the PerfectoMobileBasicTest
    *   This basic test handles the driver and the device
    */
    public abstract class PerfectoMobileBasicTest implements Runnable{

        String _DeviceId = null;
        IMobileDriver _driver;
        boolean _status = true; 

        @Override
        public void run() {
            try
            {
                execTest();
            }catch (Exception e)
            {
                _status = false; 
            }

            closeTest();
            getRep(MediaType.HTML);
        }


        public PerfectoMobileBasicTest (IMobileDriver driver)
        {
            _driver = driver;
        } 



        public Boolean getStatus() {
            return _status  ;
        }

        public void setDeviceID(String Device) {
            _DeviceId= Device;
        }

        public String  getRepName() {
            String className = this.getClass().getName();
            String name = Constants.REPORT_LIB+className+_DeviceId+".HTML";
            return  name;

        }
        public void getRep(MediaType Type) {
            InputStream reportStream = ((IMobileDriver) _driver).downloadReport(Type);

            if (reportStream != null) {
                File reportFile = new File(getRepName());
                FileUtils.write(reportStream, reportFile);
            }
        }

        public  void sleep(long millis) {
            try {
                Thread.sleep(millis);
            } catch (InterruptedException e) {
            }
        }

        public  void closeTest( ) {
            _driver.quit();

        }


        public abstract void execTest() throws Exception ;
    }*
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import com.perfectomobile.selenium.api.IMobileDevice;
    import com.perfectomobile.selenium.api.IMobileDriver;
    import com.perfectomobile.selenium.api.IMobileWebDriver;
    /*
    *
    *   Class Name  : PerfectoTestCheckFlight
    *   Author      : Uzi Eilon <uzie@perfectomobile.com>
    *   Date        : Dec 6th 2013  
    *   
    *   Description :
    *   Mobile web test 
    *   the test go to united.com (on a real device) and check the status of flights number 84
    *   it use a web driver which connected to Perfecto Mobile cloud.
    *   the test is based on a  webDriver test 
    */
    public class PerfectoTestCheckFlight extends PerfectoMobileBasicTest implements Runnable{
        public PerfectoTestCheckFlight(IMobileDriver driver) {
            super(driver);
        }

        @Override
        public void execTest() {

            IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId);
            device.open();
            device.home();

            //device.getScreenText()
            //device.checkpointText("search");
            WebDriver webDriver = device.getDOMDriver ("www.united.com");
            webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
            webDriver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
            //sleep(2000);

             question?
            String url = webDriver.getCurrentUrl();
            String title = webDriver.getTitle();
            System.out.println("url: " + url + ", title: " + title);

            WebElement webElement = webDriver.findElement(By.xpath("(//#text)[53]"));
            webElement.click();

            webElement = webDriver.findElement(By.xpath("(//@id=\"FlightNumber\")[1]"));
            webElement.sendKeys("84");
            webDriver.findElement(By.xpath("(//INPUT)[5]")).click();

        }*
于 2018-06-15T02:53:05.067 回答