Locate and activate hyperlink using RSelenium

My script below interacts with a Japanese geolocation website, successfully accesses a new page, but encounters issues locating and clicking on a specific link using RSelenium.

library(XML)
library(RSelenium)

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "firefox"
)

remDr$open()
remDr$navigate("https://maps.gsi.go.jp")
remDr$screenshot(display = TRUE)
remDr$getCurrentUrl()

webElem <- remDr$findElement(using = "id", value = "query")
webElem$getElementAttribute("id")
webElem$highlightElement()
webElem$sendKeysToElement(list("茨城県行方郡玉造町","\uE007"))
remDr$screenshot(display = TRUE)

I'm aiming to click on the node displayed below in order to extract the URL from the subsequent page. However, all my strategies involving remDr$findElement have proven ineffective. Could there be an essential step or approach that I am overlooking?

<a href="javascript:void(0);" style="padding-left: 32px; background: url(&quot;image/mapicon/search_result.png&quot;) 0px 50% no-repeat;"><div class="title">茨城県行方郡</div><div class="muni">茨城県行方市</div></a>

Answer №1

Is this the correct way?

element <- remDr$findElement(using = "css selector", value = ".city")
element$highlightElement()
element$clickElement()
remDr$getCurrentUrl()

Answer №2

When utilizing XPath :

remDr$navigate("https://maps.gsi.go.jp")
webElem <- remDr$findElement(using = "xpath","//input[@id='query']")
webElem$clickElement()
webElem$sendKeysToElement(list("茨城県行方郡玉造町", key = "enter"))

webElem2 <- remDr$findElement(using = "xpath","//div[@class='searchresultdialog_ul_frame']//a")
webElem2$clickElement()

In case of encountering errors, you can utilize a while/Trycatch combination (all credit to @Victor Burnett) to ensure the element's presence is waited for.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the best ways to change the styling of jquery ui widgets?

Currently utilizing jQuery UI, I have encountered an issue with the font size within a dialog. When utilizing the standard settings, the font size appears to be excessively large. To address this, I used the element inspector to identify the class name o ...

Vertically align elements within a bootstrap "card-body" with a fixed height inside a "card text-center" container

I need assistance with centering the h4 and button vertically on the page. Can someone help me achieve this? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89ebe6 ...

I'm noticing my table collapsing as I move around the div elements - any idea why this is happening

A challenge I am facing is creating a dynamic table where users can drag and drop colored boxes with animated transitions. While it mostly works well, sometimes the table collapses inexplicably. Here are steps to reproduce the issue: Move 100 - 400 Move 1 ...

The div element is refusing to display the background image

I'm struggling to add images as background to a div. When I try inline styling, the background-image appears fine. However, when I attempt to use an external CSS file, the image does not show up. I have carefully checked the link and made sure that t ...

Error with manual scaling of colors and shapes in ggplot2

I am trying to create unique color and shape combinations by using 4 colors (red, blue, green, and black) with 4 different shapes (shape numbers 15,16,17,19). I thought I had successfully assigned these combinations in my code below, but while the colors c ...

Issue with CSS background inner shadow not covering entire background area

A question has arisen regarding the implementation of an inner shadow effect for a background picture that is set to repeat. The current code used for the shadow effect is as follows: background: #202020 url(images/img01.jpg) repeat; -moz-box-shadow: inse ...

The ggsave() function does not apply bold formatting to text, and it also modifies the font of all text within the plot instead of just

While working on a ggplot2 chart, I encountered an issue with the ggsave() function not delivering the expected outcome. require(ggplot2) require(showtext) showtext_auto() hedFont <- "Pragati Narrow" font_add_google( name = hedFont, family = hedFo ...

Add a <div> element to a webpage in a random location every time the page is refreshed

I have a variety of 2 types of <div>s displayed on a single page. Collection 1 consists of: <div class="feature">content 1</div> <div class="feature">content 2</div> ...and so forth. Collection 2 consists of: <div class ...

Placing an eye icon on the password input field for optimal visibility and positioning

I am currently working on a Node.js project and I am attempting to incorporate an eye icon using Bootstrap into the password input field for visibility. Below is the code snippet of my input field: <div class="container"> <form ...

Hovering over graphics for automatic scrolling

I have successfully implemented a hover effect that scrolls down an image inside a div. However, I am facing an issue with making the scroll longer for images of varying lengths by using calc inside the transition property. Below is the code snippet that ...

Is there a way to customize the color of the collapsible menu?

I am currently delving into Bootstrap to enhance my skills. I decided to utilize the example navbar provided in the documentation: <nav class="navbar navbar-expand-lg navbar-light bg-primary"> <div class="container-fluid"&g ...

Combining two datasets with varying row counts, linked by a shared column, resulting in the introduction of missing values

I am currently attempting to merge two datasets in R with varying numbers of rows, matching them based on a common column and creating NA values where there is no match. However, I am experiencing issues as the merged data frame is automatically filling va ...

Show a checkmark or X depending on the condition in Javascript

I have an array of data that I want to compare to the input in a text field. If the input matches an element in the array, I want to display a checkmark, and if it doesn't match, I want to display a crossmark. However, I'm having an issue where ...

What are the best techniques for utilizing a dynamic ID field when utilizing JavascriptExecutor in conjunction with getElementById?

I'm currently trying to execute a Selenium script that will extract the text displayed on the screen after a user inputs data into a dynamic search field. Although I am able to input the text and view the results on the screen, my JavaScript code for ...

Angular JS has a unique feature of a scrollable drop-up menu that allows

https://i.sstatic.net/MOUqO.pngHere is the code snippet for my Dropup component: <div class="dropup"> <button class="btn btn-primary btn-raised dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false> ...

Creating a Form with HTML and CSS

I am currently working on setting up a banner that includes an overlay with a cutout. Beneath the overlay, there is an image. My goal is to create this design using HTML and CSS. I have been experimenting with pseudo-elements but I am having difficulty re ...

Establishing identity within a pair-wise longitudinal dataset

I am analyzing bank-firm level lending panel data, where loans from multiple banks to various firms in a country are recorded on a monthly basis. I intend to run a panel data fixed effects regression for my analysis. To do this, I need to format the data a ...

Obtain several dropdown menus without their items displaying beneath the correct element

I'm currently in the process of setting up multiple drop down menus within a navigation element. The issue I'm facing is that when a user hovers over the menu items, the displayed elements appear below the first item instead of the selected one. ...

The undirected igraph plot reveals clear spacing between the edge and the vertex at one end of the edge

Imagine showcasing a basic undirected graph created using the igraph package. library(igraph) edges = matrix(c(1,2), nrow=1, ncol=2) g = graph.edgelist(edges, directed=FALSE) set.seed(42) plot(g, edge.width=2, vertex.size=30, edge.color='black' ...

Enhancing jQuery Mobile listview with voting buttons on each item row

I am looking to incorporate 2 vote buttons within a jQuery mobile listview, positioned on the left-hand side and centered within each list item. While I have managed to achieve this using javascript, my goal is to accomplish it without any additional scrip ...