Search code examples
pythonangularjsseleniumwebautomation

While Selecting dropdown in AngularJS application from Python Selenium got an exception


I want to select drop down in AngularJS application from Python Selenium,But in my case i have <i class="dropdown icon"/> instead of <select> when i tried to use Select class its throwing an exception like "Select only works on <select> elements, not on <i>"

So can you please explain how can i select the element in the drop down list.

Thanks, Ranjith Ganapuram


Solution

  • You can't use the select class here because it is not a <select> you are trying to target. What you are trying to do is targeting an angular dropdown. You will have to write you own methode for this. probably by first clicking the dropdown element and wait for the dropdown to open, then click the element you want to select.

    <div class="text">CS47L90</div>
        <div class="menu transition hidden" tabindex="-1">
            <!-- ngRepeat: item in items --> 
            <div class="item ng-binding ng-scope active selected" ng-repeat="item in items" data-value="1" style="">CS47L90</div>
            <!-- end ngRepeat: item in items --> 
            <div class="item ng-binding ng-scope" ng-repeat="item in items" data-value="2">CS47L91</div>
            <!-- end ngRepeat: item in items --> 
            <div class="item ng-binding ng-scope" ng-repeat="item in items" data-value="3">WM1840</div> 
        </div>
    </div>
    

    so first target the div class="text">CS47L90</div>, let the webdriver wait to open the list and then click you item like <div class="item ng-binding ng-scope" ng-repeat="item in items" data-value="3">WM1840</div>