I am trying to collect URLs from a webpage with Rselenium, but getting InvalidSelector error
Use R 3.6.0 on Windows 10 PC, Rselenium 1.7.5 with Chrome webdriver (chromever="75.0.3770.8")
library(RSelenium)
rD <- rsDriver(browser=c("chrome"), chromever="75.0.3770.8")
remDr <- remoteDriver(port = 4567L, browserName = "chrome")
remDr$open()
url <- "https://www.aph.gov.au/Senators_and_Members/Parliamentarian_Search_Results?q=&mem=1&par=1&gen=0&ps=96"
remDr$navigate(url)
tt <- remDr$findElements(using = "xpath", "//a[contains(@href,'http://twitter.com/')]/@href")
I expect to collect URLs to Twitter accounts of politicians listed. Instead I am getting the next error:
Selenium message:
invalid selector: The result of the xpath expression "//a[contains(@href,'http://twitter.com/')]/@href" is: [object Attr]. It should be an element.
(Session info: chrome=75.0.3770.80)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '4.0.0-alpha-1', revision: 'd1d3728cae', time: '2019-04-24T16:15:24'
System info: host: 'ALEX-DELL-17', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: unknown
Error: Summary: InvalidSelector Detail: Argument was an invalid selector (e.g. XPath/CSS). class: org.openqa.selenium.InvalidSelectorException Further Details: run errorDetails method
When I make a similar search for very specific element all works fine, example:
tt <- remDr$findElement(value = '//a[@href = "http://twitter.com/AlboMP"]')
then
tt$getElementAttribute('href')
returns me URL I need
What am I doing wrong?