Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't select option when there are 2 options with value "-1" and "1" [fixed] #71

Closed
gabyngsp opened this issue Oct 19, 2019 · 12 comments
Closed
Labels

Comments

@gabyngsp
Copy link

gabyngsp commented Oct 19, 2019

In the form, there is a selector with the following option values.

<select id="child-age">
<option value="-1">Age</option>
<option value="0">Under 1</option>
<option value="1">1</option>
<option value="2">2</option>

Using tagui python library, i have the following code to select the option value "1"

t.click('//select[@id="child-age"]')
t.wait(1)
t.select('//select[@id="child-age"]','1')

When I run the above, it could not select the correct select option.
I did a test to first select option value '2' and it was successfully. Then I change the selection value from '2' to '1', instead of selecting '1', it selected the option with value '-1'.

@kensoh
Copy link
Member

kensoh commented Oct 19, 2019

Thanks for raising this! Your code looks correct and what you observed is not the expected behaviour.

Can you provide the website URL and the code to navigate to this step so that I can take a look?

@kensoh kensoh added the query label Oct 19, 2019
@gabyngsp
Copy link
Author

gabyngsp commented Oct 19, 2019 via email

@kensoh kensoh changed the title Unable to select the correct option when there are 2 options with value "-1" and "1" Unable to select correct option when there are 2 options with value "-1" and "1" Oct 19, 2019
@kensoh kensoh changed the title Unable to select correct option when there are 2 options with value "-1" and "1" Can't select correct option when there are 2 options with value "-1" and "1" Oct 19, 2019
@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

This is a fine piece of automation code. Some comments -

  1. Expedia website might have changed, when I run it can't work on it. And the child age is now separated to children 2 years old and above or infants below 2 years old (image below)

Screenshot 2019-10-20 at 9 44 02 AM

  1. I can't replicate the issue you are facing, in fact, there isn't any option value with -1, only the value matching the age to be selected, and 0 to mean under 1. Maybe website has been updated. (image below)

Screenshot 2019-10-20 at 9 51 08 AM

  1. Using below works for me to select the correct age for child and for infant. There is no need to do a click() before using select(). Also, the element identifier will find a best match based on the priority in the API reference, so using below directly works (working result in below image)
t.select('gcw-child-age-1','2')
t.select('gcw-infant-age-1','1')

Screenshot 2019-10-20 at 9 49 09 AM

@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

PS adding on a tip -

You used tu.wait_for_pageload('//select[@id="child-count"]') but tagui_util was not given in above attachment. There is no need to define custom function to wait for an element to appear.

You can do it by defining a max timeout (default is 10s) that is suitable for the webpage to load, and use hover() to wait until that element appears. Since hover function doesn't do anything than move the mouse to the element, it does not have any impact to the automation sequence.

t.timeout(60)
t.hover('//select[@id="child-count"]')

@gabyngsp
Copy link
Author

gabyngsp commented Oct 20, 2019 via email

@gabyngsp
Copy link
Author

gabyngsp commented Oct 20, 2019 via email

@kensoh kensoh added bug and removed query labels Oct 20, 2019
@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

Thanks! Bug found in upstream TagUI project -

In tagui_header.js, the following line

if (!found && opt.value.indexOf(valueToMatch) !== -1)

has to be changed to the following

if (!found && opt.value == valueToMatch)

The original design was to match when the option contains the value provided. But this loose definition clearly now encounters an edge case where the values are '-1', '0', '1', '2', '3'.. Providing '1' as value would match with '-1' since '-1' contains '1'). Making this change may cause some existing user scripts to fail (assuming that the search is based on contains). But is necessary change, otherwise, there is no way to click on the option with '1', as spotted in this edge case.

@gabyngsp
Copy link
Author

gabyngsp commented Oct 20, 2019 via email

@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

ETA - 30 minutes

@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

Issue and PR implemented in upstream TagUI project

kensoh added a commit that referenced this issue Oct 20, 2019
fix implemented upstream, see #71 for details
@kensoh
Copy link
Member

kensoh commented Oct 20, 2019

Implemented in TagUI for Python v1.15, fix available with pip install tagui --upgrade

@kensoh kensoh changed the title Can't select correct option when there are 2 options with value "-1" and "1" Can't select option when there are 2 options with value "-1" and "1" [fixed] Oct 20, 2019
@gabyngsp
Copy link
Author

Upgraded and verified the fix. Thank you for the quick turnaround.

@kensoh kensoh closed this as completed Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants