Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I click a link in a webpage in Rselenium?

Tags:

r

I know this should be simple, I'm just not sure why this is not working! Please help. I have the following code:

RSelenium::startServer()
require(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "localhost" 
                  , port = 4444
                  , browserName = "safari"
)
remDr$open()
remDr$navigate("http://www.cs.ucr.edu/~mshok002/")

Next, I need to click on the link "Teaching" at the top of the page and I'm stuck here. The html code is here at the following I'm just not sure how to find it using remDr$findElement. How can I search for both the link "Teaching" and html code "Teaching.html"?

<a href="Teaching.html">Teaching</a>

Thanks much

like image 559
Mohammad Avatar asked Apr 23 '15 18:04

Mohammad


People also ask

How do I click on a specific link in Selenium?

To click a link, we can use the link text locator which matches the text enclosed within the anchor tag. We can also use the partial link text locator which matches the text enclosed within the anchor tag partially. NoSuchElementException is thrown if there is no matching element found by both these locators.

How do I access links in Selenium?

A linkText is used to identify the hyperlinks on a web page. It can be determined with the help of an anchor tag (<a>). In order to create the hyperlinks on a web page, you can use anchor tags followed by the linkText.

What is click () method in Selenium?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it. A button in html code is represented by button tagname.

Can we use HREF in Selenium?

We can click a link by href value with Selenium webdriver. To identify the link with the href attribute we can take the help of the locators xpath or css selector.


1 Answers

I figured out how to do it so I'm posting my answer which may be helpful for others. I came up with two approaches: First:

remDr$navigate("Teaching.html")

Second:

webElem <- remDr$findElement(using = 'css selector',"Teaching")
webElem$clickElement()
like image 165
Mohammad Avatar answered Oct 12 '22 23:10

Mohammad