in reply to Selenium::Firefox: problem finding a child_element

G'day samberman,

Welcome to the Monastery.

I searched for pageView in the source of http://shop.tcgplayer.com/yugioh/abyss-rising/abyss-dweller. It wasn't found!

On the web page, I see a "Login" link. Did you log in before navigating to this page? That could change the content.

In the source HTML, I see a lot of the content is generated with JavaScript. Furthermore, some of the JavaScript code appears to be dynamically generated; for instance, I see 'var SHIPPINGCOUNTRY = 'AU';' in one <script>...</script> element (I'm in Australia) and that's reflected in the web page under "Shipping Country" (bottom left corner).

Anyway, without being able to see the same markup as you've posted, here's some things to try:

— Ken

Replies are listed 'Best First'.
Re^2: Selenium::Firefox: problem finding a child_element
by samberman (Novice) on Dec 22, 2015 at 14:31 UTC

    Thank you, Ken and everyone who responded. Ken, you had the answer. I tried my $child = $firefox->find_child_element($elem, "./select/option[\@value='50']"); and then a call to mouse_move_to_location and then to click and when I then retrieved the contents again, the 50 was selected. Thank you.

    Note that if you inspect the element rather viewing the source, you'll be able to see what I represented -- which is also found in the $content variable

    I have yet another, similar problem (to select an option which, in this case is part of an html "li" child element. Maybe you can help. The html is:

    <ul class="listOfChoices"> <li style="display:none" class="clear-filter"><a onclick=" +clearFilter('Condition', 67287, 'yugioh')" href="javascript:void(0)"> +Clear</a></li> <li class=""> <a onclick="changeFilter('Condition', 'NearMint', +67287, 'yugioh')" href="javascript:void(0)"> <span class="option"></span> Near Mint </a> </li> <li class=""> <a onclick="changeFilter('Condition', 'LightlyPlay +ed', 67287, 'yugioh')" href="javascript:void(0)"> <span class="option"></span> Lightly Played </a> </li> ….
    and I want to select the "Near Mint" selection. I can find the "listOfChoices" element. I am (as you can tell) not familiar with xpath, but reading through it.

    Also, how does one print an element?

      Glad to see one of my suggestions led to a solution. :-)

      As to your additional questions, I'm unfortunately strapped for time (due to airlines still unwilling to tailor their flight plans to my personal needs). Here's some hurried (and untested) suggestions.

      From the Abbreviated Syntax link I provided above, see

      • /book/chapter[5]/section[2] selects the second section of the fifth chapter of ...
      • It looks like you need li[2] (note these indices are 1-based - as opposed to 0-based array indices).

      • text() selects all text ...

        Possibly answers "how does one print an element?".

      A recent post I made (Re^2: Trouble capturing multiple groupings in regex) has some additional XPath examples. In particular, see the "more involved for loop" (in the spoiler) for printing an entire element.

      — Ken

        Thank you once again.

        After printing the element (on 2nd problem now), I realized that there was more than one of this type so I retrieved them as an array and went through until I found one with matching text. Then I looked more carefully at the child element and went to the root.... $child = $firefox->find_child_element($matched_parent, "./li/a/span[\@class='option']");

        The one I want, "Near Mint" is the first one that should match all that. When I retrieve the text (get_text), it retrieves nothing, but when I click it, it did select it and that is what I am after. I may wish to experiment with find_child_elements to see if there is some data there to ensure a match, but for now; I have working code.

        Thanks again. The perlmonks -- A valuable place for all of us!