简体   繁体   中英

Issue finding html tag with package RSelenium in a specific website

I'm using RSelenium to do some webScraping on the website https://unicancer.sigaps.fr/ . I want to rewiew 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 blablabla). I want to automatize, the collect 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 idnetify the html elements:

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

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

Here my whole code (maybe it is a docker problems? I don't really know what it is thought 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)

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 .

在此处输入图像描述

#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))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM