Reputation: 1573
On the following web site: https://www.bhtelecom.ba/index.php?id=7226&a=new I want to choose second value in drop down window ("Tuzlanski (035)") that apperad after you click on "Sarajevo (033)". I want to do that using RSelenium.
I tried 10 different solutions I found on stackoverflow but non of it works. I thinks it is because it is generated by javascript.
One of my tried solution:
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L,
browserName = "chrome")
remDr$open()
remDr$navigate("https://www.bhtelecom.ba/index.php?id=7226&a=new")
option <- remDr$findElement(using = 'xpath', "//select[@id='di']/option[@value='035']")
option$clickElement()
Upvotes: 1
Views: 935
Reputation: 5647
Firstly you have to click on input field:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
then options will be visible and you can select them using right xPath
:
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
Probably you will may need to use this:
Sys.sleep(5) # wait 5 seconds
if the script will be too quick and will try to select dropdown element before dropdown will appear.
Summary code:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
Sys.sleep(5) # wait 5 seconds
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
Upvotes: 1