It would be awesome if you could help me with the following:
I am using Rselenium and Firefox to explore the following website: https://hcupnet.ahrq.gov/#setup
I am stuck by not being able to scroll down on dropdown menus using the down_arrow, nor using window.scrollBy(0,1200). My objective is to get to a diagnosis down the list that is not visible at first and select it.
The full x-paths used are provided in the code, but if you prefer exploring via your browser the clicks are:
- Create new analysis
- Community
- Single year
- Arizona
- Counties
- Diagnosis Procedure
- Diagnosis CSS
- Choose your diagnosis dropdown
I am finding the problem in the choose your diagnosis dropdown. My objective is to select a diagnosis like "27 Cancer of ovary", which is down on the list and not visible at first.
# Stackoverflow question
library(RSelenium)
library(wdman)
library(rvest)
library(tidyverse)
# Open docker -------------------------------------------------------------
remDr <- rsDriver(port = 4443L,
browser = "firefox")
remDr2 <- remDr[["client"]]
# Navigate landing website ------------------------------------------------
# Set window size
remDr2$setWindowSize(1280L, 1024L)
# Open landing website
remDr2$navigate("https://hcupnet.ahrq.gov/#setup") #Entering our URL gets the browser to navigate to the page
Sys.sleep(2)
# Function to explore xpaths ----------------------------------------------
click_xpath <- function(xpath){
webElem <- remDr2$findElement(using = 'xpath', value = xpath )
remDr2$mouseMoveToLocation(webElement = webElem)
remDr2$click(1)
Sys.sleep(2)
}
# Landing Page ------------------------------------------------------------
# Landing page paths
landing_xpaths <- c(
'/html/body/div[1]/div/section[1]/div[3]/div[1]/button[1]', # 1. Create new analysis,
'//*[@id="DS_COMM"]', # 2. Press community
'//*[@id="YEAR_SINGLE"]', #3. Press single year,
'/html/body/div[2]/div/div/div/div/div/div[2]/div[3]/section/div/div/button/span[1]', #4. Press state dropdown,
'/html/body/div[6]/div/ul/li[2]/a', #5. Press Arizona
'//*[@id="CL_COUNTY"]', #6. Press county
'//*[@id="DP"]', # 7. Press diagnosis procedure
'/html/body/div[2]/div/div/div/div/div/div[2]/div[6]/section/div/div/button/span[1]', #8 Press dropdown category
'/html/body/div[6]/div/ul/li[2]/a', #9. Press diagnosis (CSS)
'/html/body/div[2]/div/div/div/div/div/div[2]/div[7]/section/div/div/button/span[1]' ) #10. Press Diagnosis dropdown
map(landing_xpaths,click_xpath)
# Problem ------------------------------------------------------------
# I am not able to select diagnoses that are not visible, nor I am able to use the down_arrow to go down on the list.
###################################################
# Selecting: Not working
###################################################
click_xpath(" //span[@class='text'][contains(text(),'27 Cancer of ovary')]/parent::a ")
Error: Summary: MoveTargetOutOfBounds
Detail: Target provided for a move action is out of bounds.
class: org.openqa.selenium.interactions.MoveTargetOutOfBoundsException
Further Details: run errorDetails method
###################################################
# Scrolling down: Not working
###################################################
septicemia <- remDr2$findElement(using = 'xpath', value = '/html/body/div[6]/div/ul/li[1]/a')
# Notice that none works
septicemia$sendKeysToElement(list(key = "down_arrow"))
septicemia$sendKeysToElement(list(key = "down_arrow"))
septicemia$executeScript("window.scrollBy(0,1200)")

