Jump to content
UBot Underground

Clicking on elements that does not have href


Recommended Posts

I'm trying to click on elements doesn't have href, and I'm having problems.

 

Go to this link: http://tinyurl.com/ppnng4c

 

You'll see that it is a Yahoo Local page with a listing of restaurants. Under each restaurant listing, there is a link called "Directions". I want to click on "Directions" only these 2 restaurant listings "Grub Restaurant" and "Restaurant 2117".

 

I know in Ubot, there is a "Click" command, but I can't use it's offset selector because the listing maybe be at a different location everytime. I can't just use the element selector with wildcards because, then it will click "Directions" with every restaurant listing. I have to find the resturant listing by the name of the restaurant first, then click that "Directions" link somehow. I was thinking of finding the restaurant listing by name first, then using multiple child selectors until I get to "Directions" link, but I can't get it to work.

 

Please help. Thanks in advance.

Link to post
Share on other sites

Why can't you click on the restaurant link and then click on get directions from there? One way or another it seems you are going to have to zero in on a specific restaurant...

Link to post
Share on other sites

I think Duane is right, and that will be the simplest way.

 

If you really want to do that on results page, you could use a check like this:

set(#OFFSET, 0, "Global")
set(#NAME, "Grub Restaurant", "Global")
loop(10) {
    if($contains($scrape attribute($element parent($element parent($element parent($element parent($element offset(<class="get-dir">, #OFFSET))))), "outerhtml"), ">{#NAME}</a>")) {
        then {
            click($element offset(<class="get-dir">, #OFFSET), "Left Click", "No")
            wait for element(<innertext="Get Directions to here from:Close">, "", "Appear")
        }
        else {
            increment(#OFFSET)
        }
    }
}

This will check first 10 results to see if any of them contains the name you are looking for.

Link to post
Share on other sites

Why can't you click on the restaurant link and then click on get directions from there? One way or another it seems you are going to have to zero in on a specific restaurant...

 

Hi Duane, thanks for answering. In this scenario, I can just click on the restaurant link. But I often run into cases where there is no restaurant link. I just want to learn how to do it without the link for now.

Link to post
Share on other sites

I think Duane is right, and that will be the simplest way.

 

If you really want to do that on results page, you could use a check like this:

set(#OFFSET, 0, "Global")
set(#NAME, "Grub Restaurant", "Global")
loop(10) {
    if($contains($scrape attribute($element parent($element parent($element parent($element parent($element offset(<class="get-dir">, #OFFSET))))), "outerhtml"), ">{#NAME}</a>")) {
        then {
            click($element offset(<class="get-dir">, #OFFSET), "Left Click", "No")
            wait for element(<innertext="Get Directions to here from:Close">, "", "Appear")
        }
        else {
            increment(#OFFSET)
        }
    }
}

This will check first 10 results to see if any of them contains the name you are looking for.

 

Hi UbotDev.com, thanks for that code. I see that it probably can do the job.

 

But I wonder if there is a simpler way.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...