Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

html - How to find the right node in Rselenium to press load more buttom on dynamic webpage

I want to click the [more recipes](in german: [mehr Rezepte]) Button via Rselenium on the following webpage: https://migusto.migros.ch/de/rezept-uebersicht/mexiko

I tried the following:

rD<-rsDriver(browser = 'chrome', port = 427L, chromever = '87.0.4280.88')
remDr<-rD$client

remDr$navigate('https://migusto.migros.ch/de/rezept-uebersicht/mexiko')

load_btn <- remDr$findElement(using = 'class', value = '.icon-right')
load_btn$clickElement

Does someone know how to find the right input into findElement() to get the button clicked via Rselenium?

Thank you a lot and BR David


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Rselenium is able to find different types of element inside the html page. You can use one of these elements.

findElement( using = c("xpath", "css selector", "id", "name", "tag name", 
"class name", "link text", "partial link text", "tag name", "xpath"), 
value ="the code that you find in the html page")$clickElement()

class name : Returns an element whose class name contains the search value; compound class names are not permitted.

css selector : Returns an element matching a CSS selector.

id : Returns an element whose ID attribute matches the search value.

name : Returns an element whose NAME attribute matches the search value.

link text : Returns an anchor element whose visible text matches the search value.

partial link text : Returns an anchor element whose visible text partially matches the search value.

tag name : Returns an element whose tag name matches the search value.

xpath : Returns an element matching an XPath expression.

Belwow a small example:

library(RSelenium)
rD<-rsDriver(browser = 'chrome', port = 428L, chromever = '87.0.4280.88')
remDr<-rD$client
remDr$navigate('https://migusto.migros.ch/de/rezept-uebersicht/mexiko')
remDr$findElement(using = 'xpath', value = '//*[@id="top"]/div[3]/main/div[1]/div/div[2]/form/a')$clickElement()

If you want to deep the argument here the official documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...