-
Notifications
You must be signed in to change notification settings - Fork 669
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
Comments
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? |
expedia_flight_search.py is the main code
testSearch.py is the test script for the above main code
I have tagui version 1.13.0 installed with python 3.6.9.
…On Sat, Oct 19, 2019 at 5:52 PM Ken Soh ***@***.***> wrote:
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#71>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMPZB4JR2O2TD35BIM7TQW3QPLKFDANCNFSM4JCOQYYA>
.
--
Regards
Gaby Ng
import tagui as t
import tagui_util as tu
from datetime import datetime as dt
def child_infant_breakdown(children_age):
get_indexes = lambda x, xs: [i for (y, i) in zip(xs, range(len(xs))) if x > y]
infant_index = get_indexes(2,children_age)
child_age = []
infant_age = []
for idx in range(0,len(children_age)):
if idx in infant_index:
infant_age.append(children_age[idx])
else:
child_age.append(children_age[idx])
return child_age, infant_age
def number_of_travellers(adult_pax, children_pax, children_age):
print(f"Adults: {adult_pax} and Children: {children_pax}")
t.click(f'//select[@id="adult-count"]')
t.select('//select[@id="adult-count"]', f'{adult_pax}')
# set the number of child travellers
t.click(f'//select[@id="child-count"]')
t.select('//select[@id="child-count"]', f'{children_pax}')
# Set the age for each child traveller
if children_pax > 0:
for m in range(0,children_pax):
print(f'Child {m+1} age {str(children_age[m])}')
t.click(f'//select[@id="child-age-{m+1}"]')
t.wait(1)
t.select(f'//select[@id="child-age-{m+1}"]',str(children_age[m]))
t.wait(1)
def one_way_trip(enquiry):
start_date = dt.strptime(enquiry["dates"][0], '%d/%m/%Y')
t.click('//input[@id="flight-type-one-way-hp-flight"]')
t.type('//input[@id="flight-origin-hp-flight"]', enquiry["city"][0])
t.type('//input[@id="flight-destination-hp-flight"]', enquiry["city"][1])
t.type('//input[@id="flight-departing-single-hp-flight"]', '[clear]')
t.type('//input[@id="flight-departing-single-hp-flight"]', start_date.strftime("%d/%m/%Y"))
t.click('//*[@id="traveler-selector-hp-flight"]/div/ul/li/button')
t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
def return_trip(enquiry):
start_date = dt.strptime(enquiry["dates"][0], '%d/%m/%Y')
end_date = dt.strptime(enquiry["dates"][1], '%d/%m/%Y')
t.click('//input[@id="flight-type-roundtrip-hp-flight"]')
t.type('//input[@id="flight-origin-hp-flight"]', enquiry["city"][0])
t.type('//input[@id="flight-destination-hp-flight"]', enquiry["city"][1])
t.type('//input[@id="flight-departing-hp-flight"]', '[clear]')
t.type('//input[@id="flight-departing-hp-flight"]', start_date.strftime("%d/%m/%Y"))
t.type('//input[@id="flight-returning-hp-flight"]', '[clear]')
t.type('//input[@id="flight-returning-hp-flight"]', end_date.strftime("%d/%m/%Y"))
t.click('//*[@id="traveler-selector-hp-flight"]/div/ul/li/button')
t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
def multi_city_trip(enquiry):
t.click('//input[@id="flight-type-multi-dest-hp-flight"]')
travel_dates = enquiry["dates"]
numDep = len(travel_dates)
cities = enquiry["city"]
form_flightleg = (t.count('//div[@Class="cols-nested gcw-multidest-flights-container"]/div/fieldset'))
print(form_flightleg)
t.type('//input[@id="flight-origin-hp-flight"]', cities[0])
t.type('//input[@id="flight-destination-hp-flight"]', cities[1])
t.type('//input[@id="flight-departing-single-hp-flight"]', '[clear]')
t.type('//input[@id="flight-departing-single-hp-flight"]', (dt.strptime(travel_dates[0], '%d/%m/%Y')).strftime("%d/%m/%Y"))
for num in range(1,numDep):
#add new flight leg
print(f"num:{num} and form_flightleg:{form_flightleg}")
if num >= 2 and num >= form_flightleg:
t.click('//a[@id="add-flight-leg-hp-flight"]')
t.wait(0.5)
start_date = dt.strptime(travel_dates[num], '%d/%m/%Y')
orig_city = cities[num]
if num < numDep-1:
dest_city = cities[num+1]
else:
dest_city = cities[0]
t.type(f'//input[@id="flight-{num+1}-origin-hp-flight"]', orig_city)
t.wait(0.5)
t.type(f'//input[@id="flight-{num+1}-destination-hp-flight"]', dest_city)
t.wait(0.5)
t.type(f'//input[@id="flight-{num+1}-departing-hp-flight"]', '[clear]')
t.type(f'//input[@id="flight-{num+1}-departing-hp-flight"]', start_date.strftime("%d/%m/%Y"))
t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
def fill_search(enquiry):
# Select if looking for return / one-way / multi-city
if len(enquiry["dates"]) == 1: # one way
print("one way trip")
one_way_trip(enquiry)
elif len(enquiry["dates"]) == 2: # return
print("return trip")
return_trip(enquiry)
elif len(enquiry["dates"]) > 2: # multi city
print("multi-city trip")
multi_city_trip(enquiry)
else:
one_way_trip(enquiry)
def flight_search(info):
t.url('https://www.expedia.com.sg/')
tu.wait_for_pageload('//button[@id="tab-flight-tab-hp"]')
t.click('//button[@id="tab-flight-tab-hp"]')
fill_search(info)
tu.wait_for_pageload('//button[@id="flights-advanced-options-toggle"]')
t.click('//button[@id="flights-advanced-options-toggle"]')
tu.wait_for_pageload('//select[@id="child-count"]')
adult_pax = int(info['adult'])
children_pax = len(info['child_age'])
children_age = info['child_age']
number_of_travellers(adult_pax, children_pax, children_age)
t.click('//*[@id="flight-wizard-search-button"]')
import expedia_flight_search as expedia
import tagui as t
#one way
info = {'city': ['singapore','beijing'], 'trip_type': '', 'dates': ['01/11/2019'], 'cabin_class': 'economy', 'adult': '2', 'child_age': [3,1]}
# #return
# info = {'city': ['singapore','beijing'], 'trip_type': '', 'dates': ['01/11/2019','05/11/2019'], 'cabin_class': 'economy', 'adult': '2', 'child_age': [1,3]}
# #multi-city
# info = {'city': ['singapore','beijing','tokyo'], 'trip_type': '', 'dates': ['01/11/2019','05/11/2019','10/11/2019'], 'cabin_class': 'economy', 'adult': '2', 'child_age': [3,10]}
t.init()
t.wait(0.5)
expedia.flight_search(info)
t.wait(10)
t.close()
|
This is a fine piece of automation code. Some comments -
t.select('gcw-child-age-1','2')
t.select('gcw-infant-age-1','1') |
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"]') |
I had issues with the selection from the home. So I did the initial search
using the default traveller setting on the home page of expedia.
It is in the search results page where I used the advanced options and set
the actual travellers for the flight.
…On Sun, 20 Oct 2019, 9:52 AM Ken Soh, ***@***.***> wrote:
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)
[image: Screenshot 2019-10-20 at 9 44 02 AM]
<https://user-images.githubusercontent.com/10379601/67153570-80facf80-f31e-11e9-9459-0637f589bb8e.png>
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)
[image: Screenshot 2019-10-20 at 9 51 08 AM]
<https://user-images.githubusercontent.com/10379601/67153622-32016a00-f31f-11e9-9336-22b82c2a2bd1.png>
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')
[image: Screenshot 2019-10-20 at 9 49 09 AM]
<https://user-images.githubusercontent.com/10379601/67153595-e5b62a00-f31e-11e9-89cc-a18f7720b674.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#71>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMPZB4NOFG5C4D5G3KF3U43QPO2V3ANCNFSM4JCOQYYA>
.
|
Ah.. thanks for the tips.
…On Sun, 20 Oct 2019, 9:56 AM Ken Soh, ***@***.***> wrote:
PS adding on a tip -
You used ***@***.*** <https://github.com/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)
***@***.***="child-count"]')
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#71>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMPZB4JBBCZ424U6SXR5I5TQPO3GJANCNFSM4JCOQYYA>
.
|
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. |
Any idea on ETA for the fix?
Guess I have no choice but to revert to using the main search page to do
the selection and try to resolve why the child selection ended up with 6
when I only clicked the plus sign once.
…On Sun, 20 Oct 2019, 10:27 AM Ken Soh, ***@***.***> wrote:
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#71>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMPZB4IIOMR3WRM6C3ZE3V3QPO6ZZANCNFSM4JCOQYYA>
.
|
ETA - 30 minutes |
Issue and PR implemented in upstream TagUI project |
fix implemented upstream, see #71 for details
Implemented in TagUI for Python v1.15, fix available with |
Upgraded and verified the fix. Thank you for the quick turnaround. |
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'.
The text was updated successfully, but these errors were encountered: