Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

r - dropdown boxes in RSelenium

How can one interact with dropdown boxes in RSelenium? In particular, I can select the dropdown box using findElement but how does one select an option with it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

here is the code to select a drop down list based on xpath.

Since the dropdown is inside an iframe, I have to switch into that iframe first. It probably is much easier in your situation.

New to RSelenium, check out the quick start tutorial, want to learn more about the function, refer to the pdf documentation.

require(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "firefox")

remDr$open()
remDr$navigate("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select")

iframe <- remDr$findElement(using='id', value="iframeResult")
remDr$switchToFrame(iframe)

# change audi to whatever your option value is
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'audi']")
option$clickElement()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...