2

This is my case.Two div case are the almost the same, but I need click only "Claim" from first one.Can I use background color to indentify my element? Or any other ideas?

1.

<div class="well well-sm" style="width:150px;margin:5px;text-align:center;float:left;">
  <p><b style="color:#227A11">$0.005</b></p>
  <p><a href="./seecashlinks.php?ocd=open&amp;id=96396" class="btn btn-success" style="background:#0373F1;">Claim</a></p>
</div>

2.

<div class="well well-sm" style="width:150px;margin:5px;text-align:center;float:left;">
  <p><b style="color:#227A11">$0.001</b></p>
  <p><a href="./seecashlinks.php?ocd=open&amp;id=22952" class="btn btn-success" style="background:#CC07DD;">Claim</a></p>
</div>
1
  • Can you please elaborate your question clearly and let us know what you have tried so that we can help you out? Commented Sep 9, 2015 at 8:39

1 Answer 1

3

This is how you can identify the div-element that contains an anchor element with the background color you were searching for using xpath:

driver.findElement(By.xpath("//a[@style='background:#0373F1;']/ancestor::div[1]"));

* If there are several anchor-elements with that background color on your site you would have to modify your xpath accordingly (you would need to first search for all "possible" parent elements

In your case you could for example first search for all div elements that contain class "well":

"//div[contains(@class, 'well')]/a[@style='background:#0373F1;']/ancestor::div[1]"
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.