0
<div class="jss14 jss41">
 <div class="rn-obd0qt rn-1efd50x rn-14skgim rn-rull8r rn-mm0ijv rn-13yce4e rn-fnigne rn-ndvcnb rn-gxnn5r rn-deolkf rn-6koalj rn-1qe8dj5 rn-1mlwlqe rn-eqz5dr rn-1h0z5md rn-1mnahxq rn-61z16t rn-p1pxzi rn-11wrixw rn-ifefl9 rn-bcqeeo rn-wk8lta rn-9aemit rn-1mdbw0j rn-gy4na3 rn-bnwqim rn-1lgpqti">
   <div color="#777" dir="auto" class="rn-13yce4e rn-fnigne rn-ndvcnb rn-gxnn5r rn-deolkf rn-1471scf rn-1b43r93 rn-o11vmf rn-ebii48 rn-t9a87b rn-1mnahxq rn-61z16t rn-p1pxzi rn-11wrixw rn-wk8lta rn-9aemit rn-1mdbw0j rn-gy4na3 rn-bauka4 rn-q42fyq rn-qvutc0" style="color: rgb(119, 119, 119); font-family: Roboto, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-weight: 400; text-align: justify;">$6.49</div>
 </div>
</div>

I am looking to extract the $6.49 value.

I have only found posts that have shown how to do this when the class name is static, such as:

elements = browser.find_elements_by_class_name('_2v66')

for e in elements:
    print(e.text)

How to approach this when the class name is dynamically created on click?

Edit:

More outerHTML as requested: enter image description heres://i.sstatic.net/m65D8.png

7
  • if className is dynamic then try with other locators like xpath..cssSelector.. provide bit more html code to try it out Commented Oct 19, 2018 at 16:58
  • Update the question with a bit of outerHTML Commented Oct 19, 2018 at 17:04
  • Done. Added more of the outer HTML, which is more dynamically named classes. Commented Oct 19, 2018 at 17:10
  • Can you provide the actual url? Commented Oct 19, 2018 at 18:27
  • Do you any label for this field? if there is please add that dom as well. I mean preceding sibling of <div class="jss14 jss41">? Commented Oct 19, 2018 at 18:30

1 Answer 1

1

When we don't find any unique attribute matching, then we can go with dom parent/sibiling structure or displayed text value or combining to get the unique non changing locator.

For example,

  • Here div has two immediate parent. we can take this a criteria. so div>div>div css locator will reduced result.

  • Then I guess dir="auto" is not changing, we can include that as well. So the css will be div>div>div[dir='auto']

  • If value is displayed, definitely it may have label preceding it.

Amount : $6.49

For e.g. If you have label before the div.

    <label> Amount</label>
    <div class="jss14 jss41">
      <div class="rn-obd0qt rn-1efd50x rn-14skgim rn-rull8r rn-mm0ijv rn-13yce4e rn-fnigne rn-ndvcnb rn-gxnn5r rn-deolkf rn-6koalj rn-1qe8dj5 rn-1mlwlqe rn-eqz5dr rn-1h0z5md rn-1mnahxq rn-61z16t rn-p1pxzi rn-11wrixw rn-ifefl9 rn-bcqeeo rn-wk8lta rn-9aemit rn-1mdbw0j rn-gy4na3 rn-bnwqim rn-1lgpqti">
       <div color="#777" dir="auto" class="rn-13yce4e rn-fnigne rn-ndvcnb rn-gxnn5r rn-deolkf rn-1471scf rn-1b43r93 rn-o11vmf rn-ebii48 rn-t9a87b rn-1mnahxq rn-61z16t rn-p1pxzi rn-11wrixw rn-wk8lta rn-9aemit rn-1mdbw0j rn-gy4na3 rn-bauka4 rn-q42fyq rn-qvutc0" style="color: rgb(119, 119, 119); font-family: Roboto, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-weight: 400; text-align: justify;">$6.49</div>
     </div>
    </div>

Then you can use that to find this element like,

//label[text() == 'Amount']/following-sibling::div/div/div

Please find the nearest or parent non changing value and traverse to the required element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.