Documentation Fix for find_child_element(s) #21

Closed
frezik opened this Issue Dec 21, 2011 · 3 comments

Comments

Projects
None yet
5 participants
@frezik

frezik commented Dec 21, 2011

In the documentation for Selenium::Remote::Driver::find_child_element(), it uses an xpath selector like:

my $child = $driver->find_child_element($elem1, "//option[\@value='es_ar']");

However, I've found that this does not exclusively search under the child node, and will return every option tag on the page with value="es_ar".

This version:

my @children = $driver->find_child_elements($elem1, "//option[1]");

Would return the first option tag of every select tag on the page.

I would suggest that xpath selectors be changed to search only under the given parent, but I'm not sure the way it works now is actually wrong. Using '//' at the beginning means you probably do want to search the whole page. Instead, I suggest the documentation for these two functions be fixed to use './', like:

my @children = $driver->find_child_elements($elem1, "./option[\@value='es_ar]");

This correctly searches only children of the parent element.

@gordolio

This comment has been minimized.

Show comment Hide comment
@gordolio

gordolio Dec 22, 2011

Collaborator

Here's what I've updated the documentation to. Thank you for reporting this.

=head2 find_child_element

 Description:
    Search for an element on the page, starting from the identified element. The
    located element will be returned as a WebElement object.

 Input: 3 (1 optional)
    Required:
        Selenium::Remote::WebElement - WebElement object from where you want to
                                       start searching.
        STRING - The search target. (Do not use a double whack('//')
                 in an xpath to search for a child element
                 ex: '//option[@id="something"]'
                 instead use a dot whack ('./')
                 ex: './option[@id="something"]')
    Optional:
        STRING - Locator scheme to use to search the element, available schemes:
                 {class, class_name, css, id, link, link_text, partial_link_text,
                  tag_name, name, xpath}
                 Defaults to 'xpath'.

 Output:
    Selenium::Remote::WebElement - WebElement Object
    
 Usage:
    my $elem1 = $driver->find_element("//select[\@name='ned']");
    # note the usage of ./ when searching for a child element instead of //
    my $child = $driver->find_child_element($elem1, "./option[\@value='es_ar']");

=cut
Collaborator

gordolio commented Dec 22, 2011

Here's what I've updated the documentation to. Thank you for reporting this.

=head2 find_child_element

 Description:
    Search for an element on the page, starting from the identified element. The
    located element will be returned as a WebElement object.

 Input: 3 (1 optional)
    Required:
        Selenium::Remote::WebElement - WebElement object from where you want to
                                       start searching.
        STRING - The search target. (Do not use a double whack('//')
                 in an xpath to search for a child element
                 ex: '//option[@id="something"]'
                 instead use a dot whack ('./')
                 ex: './option[@id="something"]')
    Optional:
        STRING - Locator scheme to use to search the element, available schemes:
                 {class, class_name, css, id, link, link_text, partial_link_text,
                  tag_name, name, xpath}
                 Defaults to 'xpath'.

 Output:
    Selenium::Remote::WebElement - WebElement Object
    
 Usage:
    my $elem1 = $driver->find_element("//select[\@name='ned']");
    # note the usage of ./ when searching for a child element instead of //
    my $child = $driver->find_child_element($elem1, "./option[\@value='es_ar']");

=cut

@aivaturi aivaturi closed this Feb 23, 2012

aivaturi added a commit that referenced this issue Mar 1, 2012

@rol1

This comment has been minimized.

Show comment Hide comment
@rol1

rol1 Dec 8, 2015

Hi,

you fixed the documentaion for find_child_element, but frezik also asked for "find_child_elements", would'nt it bee the same?

Yours

Roland

rol1 commented Dec 8, 2015

Hi,

you fixed the documentaion for find_child_element, but frezik also asked for "find_child_elements", would'nt it bee the same?

Yours

Roland

gempesaw added a commit that referenced this issue Dec 9, 2015

@gempesaw

This comment has been minimized.

Show comment Hide comment
@gempesaw

gempesaw Dec 9, 2015

Collaborator

Thanks :)

Collaborator

gempesaw commented Dec 9, 2015

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment