garhian
garhian

Reputation: 47

How do you click an anchor tag link using rselenium and rvest in R?

I have been practicing web-scraping in R with rselenium and rvest packages. So, for logging into many websites, a sign in button is there, which when clicked a pop-up window opens asking for the user id and password. I have been trying the following codes to click that anchor tag where sign in link is present, but none is working.

This is the html of the anchor tag (example)

<a href="/profile/login_input.htm?userOriginHook=HEADER_SIGNIN_LINK" class="track-click gd-btn-locked-transparent susiLink sign-in strong nowrap" target="_top" data-ga-lbl="Sign In"> Sign In</a>

These are the codes I have been trying :

1.

user<-remDr$findElement(using = 'href',"/profile/login_input.htm?userOriginHook=HEADER_SIGNIN_LINK")
user$sendKeysToElement(list("",key="enter"))

2.

driver.findElement(By.xpath("//a[text()='Sign In']")).click()

3.

driver.findElement(By.linkText("Sign In")).click()

4.

remDr$findElement(xpath="//a[contains(text(),'Sign In')]")).click()

Mostly, I am getting errors like unexpected symbol in this line

How to go about this? And how to send my user-id and password after pop up window opens? Thanks in advance.

Upvotes: 2

Views: 509

Answers (1)

Cya
Cya

Reputation: 367

UPDATE

In case you want to click on the Sign in button instead of straight navigating to its web address you can do the whole process as follows:

page<-"https://www.glassdoor.co.in"
remDr$navigate(page)
accept_cokies_btn <- remDr$findElement(using = "xpath", '//*[@id="onetrust-accept-btn-handler"]')
accept_cokies_btn$clickElement()
signin <- remDr$findElement(using = "xpath", '//*[@id="TopNav"]/nav/div/div/div[4]/div[1]/a')
signin$clickElement()

And after this same as previously for submitting your username and password:

username_btn <- remDr$findElement(using ="name" , "username")
username_btn$sendKeysToElement(list("add username here"))
pass_btn <- remDr$findElement(using = "name", "password")
pass_btn$sendKeysToElement(list("add password here", "\uE007"))

Note that I have added the click on one more button; the cookies accept button.

Upvotes: 1

Related Questions