alexinchinatown 2 Posted May 30, 2013 Report Share Posted May 30, 2013 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. Quote Link to post Share on other sites
Legend 181 Posted May 30, 2013 Report Share Posted May 30, 2013 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... Quote Link to post Share on other sites
UBotDev 276 Posted May 30, 2013 Report Share Posted May 30, 2013 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. Quote Link to post Share on other sites
alexinchinatown 2 Posted May 30, 2013 Author Report Share Posted May 30, 2013 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. Quote Link to post Share on other sites
alexinchinatown 2 Posted May 30, 2013 Author Report Share Posted May 30, 2013 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.