0

I'm using RSelenium to do some web scraping on the website https://unicancer.sigaps.fr/.

I want to review my team sigaps points (for those who don't know, when you publish an article in a scientific magazine, you get points and the more you have points the more you will get acknowledged). I want to automatize, the collection of those data.

So i already used RSelenium on other website and it worked, but on this specific one i can't find the html tags with those function:

remDr$findElement(using = "xpath", value = "/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input")$sendKeysToElement(list(username))
remDr$findElement(using = "name", value = "mdp")$sendKeysToElement(list(password))

I tried with the xpath and the name tag but both don"t work. I can't find any of the page elements.

I get this error:

   Selenium message:no such element: Unable to locate element: 
   {"method":"xpath","selector":"/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input"}
   (Session info: chrome=96.0.4664.45)
   For documentation on this error, please visit: 
   https://www.seleniumhq.org/exceptions/no_such_element.html
   Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
   System info: host: 'PD06B6F', ip: '10.208.107.111', os.name: 'Windows 10', os.arch: 'amd64', 
   os.version: '10.0', java.version: '1.8.0_261'
   Driver info: driver.version: unknown
 
   Error:    Summary: NoSuchElement
     Detail: An element could not be located on the page using the given search parameters.
     class: org.openqa.selenium.NoSuchElementException
     Further Details: run errorDetails method

When I'm looking on the page code with my browser I can identify the html elements:

<input name="login" class="text_box" type="text">

So the website has an issue and I need to solve the interaction problem between RSelenium and it.

Here is my whole code (maybe it is a docker problem. I don't really know what it is though I'm not a web developer)

rD <- rsDriver(browser= "chrome", port = 3955L,chromever = "96.0.4664.45")
remDr <- rD[["client"]]
 
remDr$navigate("https://unicancer.sigaps.fr/")
 
remDr$screenshot(TRUE)
 
username <- "xyz"
password <- "lol93"
 
 
remDr$findElement(using = "xpath", value = "/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input")$sendKeysToElement(list(username))
remDr$findElement(using = "name", value = "mdp")$sendKeysToElement(list(password))
 
rD$server$stop()
remDr$close()
system("taskkill /im java.exe /f", intern=FALSE, ignore.stdout=FALSE)
MLavoie
  • 9,671
  • 41
  • 36
  • 56

1 Answers1

0

We have to use switchToFrame which is generally used for iframe. Though there is no iframe for this webiste we use switchToFrame to change focus on frame.

enter image description here

#credentials
username <- "xyz"
password <- "lol93"

Start the browser

library(RSelenium)
driver = rsDriver(browser = c("firefox"))
remDr <- driver[["client"]]
remDr$navigate(url)
url = "https://unicancer.sigaps.fr/"

Now using switchToFrame to focus on frame

webElem <- remDr$findElements("css", "frame")
remDr$switchToFrame(webElem[[1]])
 remDr$findElement(using = "xpath", '//*[@id="scrollup2"]/div/font')$getElementText()

Fill in the credentials

remDr$findElement(using = "xpath", value = '//*[@id="menu_page_enveloppe"]/div[2]/form/table/tbody/tr[2]/td[2]/input')$sendKeysToElement(list(username))

remDr$findElement(using = "xpath", value = '//*[@id="menu_page_enveloppe"]/div[2]/form/table/tbody/tr[3]/td[2]/input')$sendKeysToElement(list(password))

enter image description here

Nad Pat
  • 3,129
  • 3
  • 10
  • 20
  • Good Morning Sir, It worked perfectly. Thank you for your advice ! – bouftonmouth Dec 09 '21 at 15:13
  • Yes sure ! done ^^. By the way, do you know how I can configure chrome via RSelenium to automaticaly accept prompt for excel file that I'm trying to download ? This is my final step and i'm struggling on it . – bouftonmouth Dec 10 '21 at 09:29
  • Well, I used remDr$accceptAlert() and it accepted the prompt window. So now i jus thave to find how to specify the path to the folder where I want my Excel. – bouftonmouth Dec 10 '21 at 09:57
  • To automatically download the file you can refer these answers. https://stackoverflow.com/a/65201209/12135618 or else this https://stackoverflow.com/questions/35551711/specify-download-folder-in-rselenium-does-not-work/56585364#56585364 – Nad Pat Dec 10 '21 at 11:10
  • I already checked those topics and it is not working for me. But i managed to avoid this issue by directly moving and editing file with basic R. Thank you very much for your time ! – bouftonmouth Dec 10 '21 at 12:01
  • It worked for me in chrome, maybe try again or ask a separate question. – Nad Pat Dec 10 '21 at 14:12