0

I have been trying to use RSelenium and cannot figure out how to make an 'if' 'else' statement when using the findElement function. Can anyone help out this basic problem below? This is just a test to understand a piece of my overall code. Basically, I want to see if a page has a term and if it does make a calculation. Many thanks!

Start Selenium Server --------------------------------------------------------

checkForServer()
startServer()
remDrv <- remoteDriver()
remDrv$open()


# Simulate browser session

remDrv$navigate('http://agcensus.dacnet.nic.in/districtsummarytype.aspx')

# Test if the page has the words 'District Tables' then make a calculation

if (remDrv$findElement(using = "xpath", "//*[contains(text(), 'District Tables')]"))
  {2+2}
else 
  {4+4}
Weevils
  • 312
  • 3
  • 9
  • what research have you done on the syntax – Marquis Blount Oct 14 '15 at 00:13
  • I think I am just messing up where I put the curly brackets and parentheses. I know that the lookup command works and will actually find where the page says "District Tables": remDrv$findElement(using = "xpath", "//*[contains(text(), 'District Tables') I just don't know how to test whether IF the page contains the words 'District Tables' THEN it can use that info to do a definite task. When I run the code above, the error basically says that I need the expression to return a numerical value . With the numerical value I will be able to make a IF test. Does that make sense? – Weevils Oct 14 '15 at 02:55

0 Answers0