0

I know there are other questions about this on stack overflow, but I've looked through all of those and cannot seem to make this work. My initial code is as follows:

library(RSelenium)
library(rvest)

remote_driver <- RSelenium::remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "firefox")
remote_driver$open()

# Navigate to search page
remote_driver$navigate("http://sipp.pn-pangkalanbun.go.id/list_perkara/search")

# Locate search box
search_element <- remote_driver$findElement(using = 'id', value = 'search-box')

# Enter search term
search_element$sendKeysToElement(list("Pencurian"))

# Locate search button
button_element <- remote_driver$findElement(using = 'id', value = 'search-btn1')

# Click search button
button_element$clickElement()

All of the above works, and it brings up a page of search results. I now want to make R click on the page number links at the bottom of the page to bring up further pages of results. Using the selenium extension for Chrome, I've found the following xpath values for the page 2 link:

xpath=(//a[contains(text(),'2')])[2] and xpath=(//a[contains(@href, '#page-2')])[3]

I just want to make R click on that link, but I can't seem to. I have tried both of the following lines of code:

button_element2 <- remote_driver$findElement(using = "xpath", value = "//a[contains(@href, '#page-2')])[3]")

button_element2 <- remote_driver$findElement(using = 'xpath', value = "(//a[contains(text(),'2')])[2]")

I have also tried various other iterations where I am removing the [2] and [3] at the end of the strings, but no matter what I do I get some variation of this error:

error

Can anyone help me fix this?

1 Answer 1

1

We can click by using xpath,

remDr$findElement(using = 'xpath', value = '//*[@id="selector_bottom"]/ul/li[3]')$clickElement()

Here [3] represents second page of results. For third page we can use xpath,

//*[@id="selector_bottom"]/ul/li[4]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much, this worked great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.