0

I am trying to search http links in images. If the image link contains a certain string in it, I want to check the checkbox associated with it:

I tried the following code but it does not work.

Here in the code below, I am trying to check the checkbox of the image if the image link contains the string "google".

How can I do that?

Thanks

for (i=0; i<document.getElementsByTagName('div').length; i++) 
  {

    if(document.getElementsByTagName('img')[i].evaluate(contains(@src, 'google'))
    {

        if(document.getElementsByTagName('input')[i].type=='checkbox')
        {
        document.getElementsByTagName('input')[i].checked =true;
        }
    }

  }

1 Answer 1

3

To search a specific substring inside a string you can use indexOf or a RegExp. E.g.:

document.getElementsByTagName('img')[i].getAttribute("src").indexOf("google") > -1
Sign up to request clarification or add additional context in comments.

1 Comment

thanks friend, it worked. It tells me that I need to wait 9more minutes in order to accept your answer. I will be doing that for sure!

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.