Jump to content
UBot Underground

Click one Element out of multiple (changing offset)


Recommended Posts

Hello.

 

I need to click a button on a website. There are multiple buttons of the same type. They have the exact same image and everything. 

The offset of the button I want to click changes all the time. 

 

It's structured as a table. And the only constant is that it's right after "results per page".

 

So the table element where my button is located looks like:

 

 

   <tr class="list-row">
        <td colspan="9" align="left" valign="center">
            <form style="border: 0px; margin: 0px" class="myo_list_orders_search_form" onsubmit="return MYO.LO.DoAjaxSearchCall( this );">
                <table align="left" cellpadding="3" cellspacing="0"><tbody><tr>
                    <td class="tiny" align="center">Show</td>
                    <td class="tiny" align="center">
                        <select name="itemsPerPage">
                            <option value="15" selected="">15</option>
                            <option value="25">25</option>
                            <option value="50">50</option>
                            <option value="100">100</option>
                        </select>
                              <input name="statusFilter" type="hidden" value="Default">
                              <input name="showCancelled" type="hidden" value="0">
                              <input name="sortBy" type="hidden" value="OrderStatusDescending">
                              <input name="searchFulfillers" type="hidden" value="all">
                              <input name="searchDateOption" type="hidden" value="exactDates">
                              <input name="searchType" type="hidden" value="DateRange">
                              <input name="shipExactDateEnd" type="hidden" value="6/14/14">
                              <input name="searchKeyword" type="hidden" value="">
                              <input name="paymentFilter" type="hidden" value="Default">
                                <input name="orderType" type="hidden" value="All">
                              <input name="searchLanguage" type="hidden" value="en_US">
                              <input name="byDate" type="hidden" value="orderDate">
                              <input name="preSelectedRange" type="hidden" value="exactDates">
                              <input name="shipmentFilter" type="hidden" value="Default">
                              <input name="showPending" type="hidden" value="0">
                              <input name="shipSelectedRange" type="hidden" value="7">
                              <input name="isDebug" type="hidden" value="">
                              <input name="shipSearchDateOption" type="hidden" value="shipPreSelected">
                              <input name="shipExactDateBegin" type="hidden" value="4/22/14">
                              <input name="isSearch" type="hidden" value="1">
                              <input name="exactDateEnd" type="hidden" value="6/5/14">
                              <input name="exactDateBegin" type="hidden" value="6/5/14">
                        <input type="hidden" name="currentPage" value="1">
                    </td>
                    <td class="tiny" align="center">results per page</td>
                    <td class="tiny" align="center"><input type="image" src="https://images-na.ssl-images-amazon.com/images/G/01/abis-ui/buttons/go._V187564664_.gif" width="21" align="absmiddle" height="21" border="0"></td>
                </tr></tbody></table>
            </form>
        </td>
    </tr>
 
The red part is my button. 
 
Scraping of that url is not a problem. I could also find the correct html tag via Regex or Xpath. 
 
But I don't know how to do it via click and the browser.
I played around with child , parent and sibling a little bit. But I haven't used that a lot to know how to do it. 
 
 
Would be great if someone could tell me how to identify the button object that is right after "results per page". 
But without using offset.
 
Thanks in advance for your help.
 
Dan
Link to post
Share on other sites

Dan, If you send me the site I will get the code for you that you need from a "$element offset" perspective.

 

FYI to everyone else reading this I am putting the final videos together for an updated section on my site for Parent Child Sibling training along with coding examples.  SO that will be next week for sure.

 

Buddy

Link to post
Share on other sites

Dan, If you send me the site I will get the code for you that you need from a "$element offset" perspective.

 

FYI to everyone else reading this I am putting the final videos together for an updated section on my site for Parent Child Sibling training along with coding examples.  SO that will be next week for sure.

 

Buddy

So you would recommend to work with element offset?

Parent / Child is not useful here?

 

I watched the training videos on your site, but still don't understand it 100% :-(

Dan

Link to post
Share on other sites

To be honest, element offset makes sense BUT the others my work too.  I just need to see the site and I will tell you for sure.

 

Just so you know the videos you watched are the old ones.  You have not seen my new ones yet.  I will be adding about 25 new ones next week.

 

Buddy

Link to post
Share on other sites

Hi Dan, try this:

 

click($element from text("<{$find regular expression($document text, "(?<=results per page</td>\\s*<td class=\"tiny\"\\salign=\"center\"><input\\s)type=\\\"image\\\"")}>"), "Left Click""No")

 

Marton

Link to post
Share on other sites

Hi Dan, try this:

 

click($element from text("<{$find regular expression($document text, "(?<=results per page</td>\\s*<td class=\"tiny\"\\salign=\"center\"><input\\s)type=\\\"image\\\"")}>"), "Left Click""No")

 

Marton

Thanks Marton,

 

but that's not working. The regex result is type="image"

And that is then used as input for the "Element to click" field.

 

The problem is, that there are multiple of those buttons on the page. 

I think I have to work with offset somehow. 

 

Dan

Link to post
Share on other sites

Would be great if someone could tell me how to identify the button object that is right after "results per page". 

 

I think my code does exactly that. No matter where it's situated on the page, even if there are multiple buttons like that. Isn't that what you needed?

 

EDIT: attached code I was playing with, no offset used as requested.

test.ubot

Link to post
Share on other sites

I think my code does exactly that. No matter where it's situated on the page, even if there are multiple buttons like that. Isn't that what you needed?

 

EDIT: attached code I was playing with, no offset used as requested.

The problem is probably that I need to click only one of the buttons. The one right below the "results per page" text. 

I found a solution that is working for me:

 

 

clear list(%zzz)

change dropdown(<name="itemsPerPage">, 100)

add list to list(%zzz$scrape attribute($element parent($element parent(<src=w"*buttons/go*">)), "outerhtml"), "Delete""Global")

loop($list total(%zzz)) {

    if($contains($next list item(%zzz), "results per page")) {

        then {

            click($element offset(<src=w"*buttons/go*">$add($list position(%zzz), 1)), "Left Click""No")

        }

    }

}

  • Like 1
Link to post
Share on other sites

The problem is probably that I need to click only one of the buttons. The one right below the "results per page" text.

 

Doesn't my code do that? That's why I included the "results per page" in my regex. Obviously you could optimize the regex, but the one I posted should only click the one right after "results per page".

Link to post
Share on other sites

Doesn't my code do that? That's why I included the "results per page" in my regex. Obviously you could optimize the regex, but the one I posted should only click the one right after "results per page". Doesn't it?

No. The regex extracts type="image"

And that is used as input for click element. But how should the click command know which of the 6 type="image" elements on the page it should click?

 

The regex "only" extracts a text part of the element. But it's not something unique. type="image"  is 6x on that page.

 

The correct element offset is required to identify the right button element out of 6 on the page. 

 

Dan

Link to post
Share on other sites

Well, when you are ready for the Parent/Child/Sibling/Offset just let me know what the website is.

 

Good Luck in the mean time.

 

Buddy

 

I like Dan's solution, but I too would like to see how you would do it.

 

Like this?

 

click($element child($element sibling($element sibling(<innertext="results per page">))), "Left Click""No")

 

EDIT: This works with the example script, I think this is what you were looking for Dan. Let me know if this works for you on your actual page.

Link to post
Share on other sites

I don't like working from HTML shown like that.  The absolute BEST way to generate good code is from seeing and touching the website firsthand.  But that's me.

 

With what I know about Parent/Child/Sibling coding something appears to be missing.

 

Buddy

  • Like 1
Link to post
Share on other sites

Well, when you are ready for the Parent/Child/Sibling/Offset just let me know what the website is.

 

Good Luck in the mean time.

 

Buddy

Hi Buddy,

 

It's:

https://sellercentral.amazon.com

You need an Amazon Seller account. And some Orders in the system to have access to the order overview page. 

 

Kindest regards

Dan

Link to post
Share on other sites

With what I know about Parent/Child/Sibling coding something appears to be missing.

 

Buddy

 

What do you mean?

 

If you look at the example html you can notice that the needed element is the child of the next sibling. I needed to use next sibling twice because of the line break (<br>) which is also considered as a sibling in this case.

My code seems to work with the example html even if you add some more buttons, but I can't do any further testing either, since I don't have an Amazon Seller Account.

 

Dan, verdict?

 

click($element child($element sibling($element sibling(<innertext="results per page">))), "Left Click""No")

Link to post
Share on other sites

What do you mean?

 

If you look at the example html you can notice that the needed element is the child of the next sibling. I needed to use next sibling twice because of the line break (<br>) which is also considered as a sibling in this case.

My code seems to work with the example html even if you add some more buttons, but I can't do any further testing either, since I don't have an Amazon Seller Account.

 

Dan, verdict?

 

click($element child($element sibling($element sibling(<innertext="results per page">))), "Left Click""No")

 

I can confirm that

click($element child($element sibling($element sibling(<innertext="results per page">))), "Left Click""No")

 

is working fine. It's clicking exactly the right button in my case.

Thanks a lot Marton for that. That's much easier than the loop offset thing I wrote.

 

I still don't understand how that sibling stuff works but it works  :D

Dan

Link to post
Share on other sites

I'm glad I could help, (especially after my initial silliness from yesterday, lol  :wacko: ).

 

Anyway, that's all there's is to it:

post-695-0-77987600-1402255160_thumb.png

 

Marton

Link to post
Share on other sites

Awesome!  Glad it works.  I tried the link Dan but my Amazon account does not work in that area...You must be "Special".  LOL

 

@Marton what I meant was it just looked off from my eyes.  I would rather work from the site itself rather than embedded html like what Dan had placed in the original post.

 

It's great to see others getting into Parent/Child/Sibling/Offset stuff.  I have been the only one for the longest time.

 

Buddy

Link to post
Share on other sites

Awesome!  Glad it works.  I tried the link Dan but my Amazon account does not work in that area...You must be "Special".  LOL

 

@Marton what I meant was it just looked off from my eyes.  I would rather work from the site itself rather than embedded html like what Dan had placed in the original post.

 

It's great to see others getting into Parent/Child/Sibling/Offset stuff.  I have been the only one for the longest time.

 

Buddy

 

Yeah I know, initially I think I learned about this stuff from your training, those are must see videos! I recommend them to everyone!

 

All the best,

Marton

Link to post
Share on other sites
  • 6 months later...

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...