I want to check whether the “div” tag content contains SomeText or not. If yes, I want to get the id value in “a” tag from that “div” tag.
I intend to use Inject Js Script to do that but I don’t know how to get that.
Please help me if you have any solution for this problem.
I had a similar issue, but I found a solution in this post How to get dynamic url. There you can find examples of js. code that I used to make my issue work.
So my code in the inject JS Script activity looked liked this:
function(e) {
var url_link = document.getElementsByClassName("_ldf")[0].children[0].href;
return url_link;
};
Which returns the url as a string.
You need to change the value after the “=” sign in order to get your value. I would suggest playing around with the console in your web browser to try to find the element you are looking for.
Edit: I tried your HTML code:
So if thats the text you need you can just replace the “document.getElements…” in the picture above, after the “=” sign and you should be able to extract the element
I really appreciate your help.
Finally, I figured out the js code to achieve my requirement as below:
function(e) {
var dDivs = document.getElementsByTagName(“div”);
var desiredText = “sometext2”;
var output = “not found”;
for (var i = 0; i < dDivs.length; i++) {
if (dDivs[i].innerText.indexOf(desiredText) !== -1) {
output = dDivs[i].getElementsByTagName(“a”)[0].getElementsByTagName(“img”)[0].id
}
}
return output;
};