0

Being new to Selenium, I have been trying to figure how to extract the value corresponding to the key under the ng-repeat, in my case, the key is status.

The partial page is as follow:

<div ng-repeat="(key, value) in lastResult" class="ng-scope">
              <div class="row">
                <div class="col-xs-4">
                  <span class="key pull-right ng-binding">status</span>
                </div>
                <div class="col-xs-8">
                  <span class="value ng-binding" ng-class="isUrl(value) ? 'ellipsis' : ''" ng-bind-html="value | highlight">1</span>
                </div>
              </div>
            </div>

<div ng-repeat="(key, value) in lastResult" class="ng-scope">
              <div class="row">
                <div class="col-xs-4">
                  <span class="key pull-right ng-binding">type</span>
                </div>
                <div class="col-xs-8">
                  <span class="value ng-binding" ng-class="isUrl(value) ? 'ellipsis' : ''" ng-bind-html="value | highlight">standard</span>
                </div>
              </div>
            </div>

Page can contain many other ng-repeats, but I am only interested in the value of the status, which is 1 in the above sample code.

I'm using selenium with python 3.

1 Answer 1

1

The idea here is to apply the findAll - filter - extract pattern.

Find all:

ng_scopes = driver.find_elements_by_class("ng-scope")

Filter:

ng_scopes_with_status_one = [ng_scope for ng_scope in ng_scopes if ng_scopes.find_element_by_css_selector(".col-xs-8 span").text == "1"]

Extract:

ng-repeat_value = ng_scopes_with_status_one[0].get_attribute("ng-repeat")
1
  • Hi João, thank you very much for your reply. I met another hurdle as in the landing page is full of javascript which I have no idea which javascript generate the abovementioned page... I guess I have to KIV this project and move on to another.
    – John
    Oct 24, 2019 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.