13

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?

Héctor Garrido
  • 171
  • 1
  • 14
Alex
  • 17,745
  • 33
  • 112
  • 182

1 Answers1

24

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

jsta
  • 2,487
  • 24
  • 29
B.Mr.W.
  • 16,522
  • 30
  • 96
  • 156
  • I do not switch the Frame,and I directly use the xpath to change the 'select' option,it works.Thanks a lot. – chunjin Jan 07 '17 at 03:29