0
我想使用RSelenium刮這個網站link。我成功地抓取了網頁上的大部分內容,但正試圖進行「設施訪問」和「設施投訴」。由於這兩個按鈕在使用開發人員工具檢查它們時都具有javascript href,因此我一直使用phantomjs和RSelenium。RSelenium拋出StaleElementReference錯誤
我可以成功地通過幻影瀏覽網頁,但每當我試圖提取使用$用getElementText領域的文字,我拋出了以下錯誤:
Selenium message:{"errorMessage":"Element does not exist in cache","request":{"headers":{"Accept":"application/json, text/xml, application/xml, */*","Accept-Encoding":"gzip, deflate","Host":"localhost:4444","User-Agent":"libcurl/7.53.1 r-curl/2.6 httr/1.2.1"},"httpVersion":"1.1","method":"GET","url":"/attribute/id","urlParsed":{"anchor":"","query":"","file":"id","directory":"/attribute/","path":"/attribute/id","relative":"/attribute/id","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/attribute/id","queryKey":{},"chunks":["attribute","id"]},"urlOriginal":"/session/c0f30500-55d0-11e7-96dd-3b147ee40d88/element/:wdc:1497974074536/attribute/id"}}
Show Traceback
Error: Summary: StaleElementReference Detail: An element command failed because the referenced element is no longer attached to the DOM. class: org.openqa.selenium.StaleElementReferenceException Further Details: run errorDetails method
,當我使用$ CURRENTURL和$ screenship(display = T)顯示正確的網站呈現和正確的鏈接。
我知道它是與如何元素附加到DOM,但我不知道如何解決這個問題中的R下面
代碼:
url <- "https://dhs.arkansas.gov/dccece/cclas/FacilityInformation.aspx?FacilityNumber=23516"
rd<-remoteDriver(browserName = 'phantomjs')
rd$open()
rd$navigate(url)
webElem<- rd$findElement(using="xpath", value = '//*[@id="ctl00_ContentPlaceHolder1_lbtnVisits"]')
webElem$clickElement()
webElem$findElements('css',"#aspnetForm > div.page > div.main")
webElem$getElementAttribute("id")