Skip to content

how to handle with DropDown Box #2

@brightbird

Description

@brightbird

Firstly, many thanks to your great work in the 'Rwebdriver' package and the book《Automated Data Collection with R 》.

I encountered a problem when I'am tring to scrap a airplane ticket website:http://english.ctrip.com/chinaflights.
I use the element_click() and keys(''Shanghai") to fill the 'From' field, while i'm trying to switch to the 'To' field, i got an error.

It seems that i should choose one of the choices of the drop down box,but i don't know how to do this using the functions in 'Rwebdriver'.

Here's my code:

define Base Url

BaseUrl<-'http://english.ctrip.com/chinaflights'

start session

start_session(root = "http://localhost:4444/wd/hub/",browser = "firefox")

post Base Url

post.url(url = BaseUrl)

test

get.url()
page_title()

Choice:one way;Round trip; Muti-City

OneWay<-element_xpath_find(value = '//*[@id="radOW"]')

Test OneWay

element_click(OneWay)

Close the Ads

Ads<-element_xpath_find(value = '//*[@id="appd_wrap_close"]')
element_click(Ads)

input:From

From<-element_xpath_find(value = '//[@id="homecity_name"]')
To<-element_xpath_find(value = '//
[@id="destcity1_name"]')

element_click(From)
keys('Shanghai')

element_click(To)
keys('Beijing')

Many thanks for your time !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions