Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

r - RSelenium issue when selecting from dropdown menu

I've looked and tried all possible alternatives found in other questions about dropdown menus with RSelenium. However for some reason none of them get this issue solved.

I'm trying to fill a form on this page consisting of 2 dropdown menus and 2 date selectors + a button press. I can't get past the first dropdown of "Empresa"

I've managed to select the appropiate element but when clicking nothing happens. Also, cannot replicate the behavior of a manual click in a Selenium click.

Hopefully someone has an insight I can apply.

library(tidyverse)
library(RSelenium)

link <- "https://www.smv.gob.pe/Frm_EVCP?data=5A959494701B26421F184C081CACF55BFA328E8EBC"
driver <- rsDriver(browser="firefox", port=4545L)
remote_driver <- driver[["client"]]
# remote_driver$open()
remote_driver$navigate(link)

Credicorp_SAF <- remote_driver$findElement(using = "xpath",value = '/html/body/form/div[3]/div[2]/div/div[2]/div[2]/div[2]/div[2]/div[2]/select/option[contains(text(), "CREDICORP CAPITAL")]')
Credicorp_SAF$clickElement() #Nothing happens in the open browser
Credicorp_SAF$getElementText() #Verifying it's the correct one

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

1 Answer

0 votes
by (71.8m points)

The page uses jQuery. You can trigger that from javascript with:

$('[name="ctl00$MainContent$cboDenominacionSocial"]').val("124863")
$('[name="ctl00$MainContent$cboDenominacionSocial"]').trigger('change')

I'm not sure how to execute that in RSelenium, apparently it's something like:

remDr$executeScript(script, args = list("dummy"))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...