Home > Blockchain >  Clicking on a custom element with Selenium (RSelenium)
Clicking on a custom element with Selenium (RSelenium)

Time:11-13

I need to click on an element with the following unique identifier:

<mat-icon
class="mat-icon notranslate icon-arrow-down-tail mat-icon-no-color"
fontset="icon-arrow-down-tail"
role="img"
aria-hidden="true">
   ::before
</mat-icon>

I think this is the proper way to select a custom-element in RSelenium:

down <- remDr$findElement(using="xpath", value="//mat-icon[@class='mat-icon.notranslate.icon-arrow-down-tail.mat-icon-no-color']")

The element is located in an iframe. I've switched to the iframe, but I imagine there could still be something more complex going on. I'm trying to narrow down what the source of the problem is.

So, my question is: did I properly select a custom element? If not, how do I do that? If I know I selected it properly, I can figure out where else to debug...

(Website is proprietary/requires a login or I'd share it).

CodePudding user response:

If an element you wish to extract the value is in an Iframe, it needs to be switched focus first and then you can proceed to take the element by ID/Class

for example, I used to click a Button inside an Iframe from a site called "https://forexsb.com/historical-forex-data"

iframe_detect <- remDr$findElements(using = "xpath", value = "//iframe[@id='data-app-frame']")
remDr$switchToFrame(iframe_detect[[1]])
load_data_element <- remDr$findElement(using="xpath", value="//button[@id='btn-load-data']")
load_data_element$clickElement()

In above what you use of defining Class element:

down <- remDr$findElement(using="xpath", value="//mat-icon[@class='mat-icon.notranslate.icon-arrow-down-tail.mat-icon-no-color']")

I guess this is a proper full class identifier, since there is multiple name of class joint with dot operator. But in my experience, if using these can come out didn't work, I use just the first class name before the dot operator

so if I had to rewrite (note: only work if there are no more element have the same class name, or else it may take the whole element which match by the Class):

down <- remDr$findElement(using="xpath", value="//mat-icon[@class='mat-icon']")
  • Related