Overview of Selenium Technique in R

Posted by Agung Pambudi in ,
I am interested in using Selenium with R. I note that the various documentation. In the documentation it notes about running a selenium server and one can use it to boost web navigation and to ease the path.

Accessing Selenium functionality from within R is possible via the Rwebdriver package.

Selenium. (source: www.ninthavenue.com.au)

# XPath expression for the button element, /html/body/div/div[2]/form/input

# returned the corresponding element ID from the live DOM and save in a new object called buttonID
R> buttonID <- element_xpath_find(value = "/html/body/div/div[2]/form/input") 

# perform the left-mouse click on the identified element and pass buttonID as the ID argument
R> element_click(ID = buttonID) 

# obtain all active window handles
R> allHandles <- window_handles() 

# to change the focus back on the window
R> window_change(allHandles[1]) 

# another option would be to close the window using close_window(). This automatically returns the focus to the previous window.

# obtaining the IDs for the input field
R> yearID <- element_xpath_find(value = '//*[@id="yearSelect"]') 
R> monthID <- element_xpath_find(value = '//*[@id="monthSelect"]') 
R> recipID <- element_xpath_find(value = '//*[@id="recipientSelect"]') 

# remove any input from a text field with the element_clear() function on the respective element.

# pass the keyboard input that we wish to enter
R> keys("2013") 

R> element_click(monthID) 
R> keys("January") 
R> element_click(recipID) 
R> keys("Barack Obama") 

# perform a mouse click on the year field by executing element_click() with the appropriate ID argument
R> submitID <- element_xpath_find(value = '//*[@id="yearForm"]/div/button') 

# identify the button using XPath and pass the corresponding ID element to the clicking function
R> element_click(submitID)

No comments:

Post a Comment