2017-02-23 1 views
1

Ich habe versucht, alle Möglichkeiten zur Automatisierung der Dropdown-Auswahl in Rselenen? Insbesondere kann ich die Dropdown-Box mit findElement auswählen, aber wie wählt man eine Option damit?RSelenium-Fehler beim Zugriff auf Dropdown-Elemente während Web-Scarping

http://localizador.extra.com.br/storeSearch/?organization=EXTRA

Ich versuche, diese Website zu kratzen.

Der Code, den ich ausprobiert habe.

for(i in 2:15){ 
#This part of code is not able to change the option in dropdown 
webElem1a <- remDr$findElements(using='xpath',paste("//[@id='state']/option[",i,"]")) 
webElem1a$clickElement() 
loadmorebuttons<- remDr$findElement(using = 'css selector',".hidde") 
loadmorebuttons$clickElement() 

Sys.sleep(5) 


#Below this code works properly 
#Check the total Number of stores Available 
    webElem1a<-remDr$findElements(using = 'css selector',".storesFound") 
    Total_stores<-unlist(lapply(webElem1a,function(x){x$getElementText()})) 
    Total_stores<-as.numeric(Total_stores) 

#Load More view 
    if(Total_stores >= 7){ 
    for(j in 1:58){ 
     abc<-remDr$findElement(using = 'css selector',".moreResults") 
     abc$clickElement() 
    } 
    }else{ 
    print("") 
    } 

Antwort

1

können Sie die selectTag Methode verwenden:

library(RSelenium) 

rD <- rsDriver(verbose = F) 
remDr <- rD$client 
remDr$navigate("http://localizador.extra.com.br/storeSearch/?organization=EXTRA") 
selElem <- remDr$findElement("id", "state") 
opts <- selElem$selectTag() 
opts$elements[[2]]$clickElement() 

rm(rD) 
gc() 
+0

Vielen Dank @jdharrison. Es hat mein Problem gelöst. – Shubham

+0

Die Verwendung von 'opts $ elements [[2]] $ clickElement()' endet mit einem Fehler 'Fehler: Versuch, eine Nichtfunktion anzuwenden'. Wie kann ich das beheben? –

Verwandte Themen