Merge lp://qastaging/~kenneth-koontz/selenium-simple-test/bug-828050 into lp://qastaging/selenium-simple-test

Proposed by Kenneth Koontz
Status: Work in progress
Proposed branch: lp://qastaging/~kenneth-koontz/selenium-simple-test/bug-828050
Merge into: lp://qastaging/selenium-simple-test
Diff against target: 46 lines (+26/-5)
1 file modified
src/sst/actions.py (+26/-5)
To merge this branch: bzr merge lp://qastaging/~kenneth-koontz/selenium-simple-test/bug-828050
Reviewer Review Type Date Requested Status
Corey Goldberg (community) Needs Fixing
Review via email: mp+75946@code.qastaging.launchpad.net

Description of the change

link_click now has the ability to locate a link by partial id. Utilizes xpath to check the children element of selected id_or_elem for a unique link.

e.g.
link_click('bugtarget-picker-tasksummary')

To post a comment you must log in.
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

I looked at the implementation and I'm wondering if this is too much magic for the link_click() action.

the problem I see is..
if we add this to the regular link_click(), we lose the ability to click links with a specific id that is a substring of other id's.

for example, say the page has the following:

<a id="foo" href="/">link</a>
<a id="foobar" href="/">link</a>

it would no longer be possible to do:
link_click('foo') and click the first link,
since link_click('foo') would do a partial match and find both links.

so..

what about leaving link_click() as-is, and adding a new action to handle this instead:

maybe something like:

def partial_link_click(partial_id, check=False, wait=True)

thoughts?

-Corey

review: Needs Fixing
Revision history for this message
Kenneth Koontz (kenneth-koontz) wrote :

Corey, great point! I actually thought about extracting functionality and putting it into another action; however, I was left with the same thing. If we give the user the ability to add partial_id's, then the user can input any substring, like the aforementioned 'foobar' example. Which means that if we want to have partial locators with id's, the user must give some thought into the locator otherwise they will be left with an assertion error.

Take for instance a dynamic website that appends a unique key every time a new post is created. Suppose the string to append the key to is postlink. We would likely see postlink1, postlink2, ... postlink{n}. Furthermore, suppose there was another link element with the id, postlink-summary. In this case, link_click('postlink') won't work; but my question is-should it? Partial matching or not, if the user provides an ambiguous selector, they should be notified and there should be no action associated with it. So in link_click's case, if there is ambiguity in 'element_locator', the following line:

"""
if not get_element_by_xpath(element_locator).get_attribute('href')
"""

should catch this ambiguity in 'get_element_by_xpath'.

"""
if len(elements) != 1:
    msg = 'Could not identify element: %s elements found' % len(elements)
    _raise(msg)
"""

Thanks!

-K

Revision history for this message
Leo Arias (elopio) wrote :

What about adding the possibility to use regular expressions?

Revision history for this message
Kenneth Koontz (kenneth-koontz) wrote :

Leo, I'm not sure how regular expressions would work in this case. Can you provide an example or your thoughts?

Corey, is your stance still the same? Would you like me to just pull out the functionality from this merge and put it into a separate function? Say, partial_link_click()? What are your thoughts?

Unmerged revisions

187. By Kenneth Koontz

#828050: link_click now has ability to locate by partial id

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches