0

My boss asked me to grab some data from the China in-depth accident study database. I know that I need to log in first so that I chose to use RSelenium and phantomjs to help me with my work.

I am a beginner to HTML and javascript and basically have no experience in it. To finish the task, I searched a lot from website to understand RSelenium. I can use it to log in any other website correctly. However, for this website http://114.255.167.200:8092/cidasEN/extend/util_login_list.do, I can not insert the username or password into the element by using sendKeysToElement.

For details, I successfully start Selenium server and can log in another accident database vufo.

My code is

remDr$open(silent = T)
remDr$navigate("https://www.vufo.de/interner-bereich/internal-area/?L=1")
wxbox<- remDr$findElement("name","user")
wxbox$sendKeysToElement(list(""))     
wxbox<- remDr$findElement("name","pass")
wxbox$sendKeysToElement(list(""))       # Type password provided from GIDAS between  inverted commas " "
wxbutton<- remDr$findElement("name","submit")
wxbutton$sendKeysToElement(list(key="enter"))  

I can successfully log in this website and grab the data I want if I insert the username and password. But for

remDr$open(silent = T)
remDr$navigate("http://114.255.167.200:8092/cidasEN/extend/util_login_list.do")
wxbox<- remDr$findElement("css selector","#name.b_1")
wxbox$sendKeysToElement(list(""))           # Type username provided from GIDAS between  inverted commas " "
wxbox<- remDr$findElement("css selector","#password.b_1")
wxbox$sendKeysToElement(list(""))    

I got the error:

Error:   Summary: InvalidElementState
 Detail: An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
 class: org.openqa.selenium.InvalidElementStateException
 Further Details: run errorDetails method

I think the problem is that this website is written with td not div. You can press F12 and check the website that Chinese website is consisted with td /td.

I dont know how to insert keys to element between td /td. It seems that it is different from div. I tried to search for the answer. But I can hardly find any solutions.

Thanks.

  • Have you run the errorDetails method as the errors says? There is fundamentally no difference for the `findElement` method whether the layout is built as a `table` or with `div`. As the problem says, it seems the target element is in invalid state - quite possibly disabled. – Martin Zikmund Dec 06 '16 at 08:05
  • Thank you for you comment. Actually I do not know how to run the errorDetails method. If the target element is in invalid state, how can I make it enabled? I once thought maybe I used the wrong way to locate the element so that I tried css selector after I used "id" or "name" to locate it. However, the result is the same, I still got the errors. – 吴浩然 Dec 06 '16 at 08:13

1 Answers1

1
library(RSelenium)
remDr<-remoteDriver()
remDr$open(silent = T)

remDr$navigate("http://114.255.167.200:8092/cidasEN/extend/util_login_list.do") 

wxbox<- remDr$findElement("css selector","#name.b_1")$clickElement() 

remDr$findElement("css selector","#name.b_1")$sendKeysToElement(list("a"))           # Type username provided from GIDAS between  inverted commas " " 

wxbox<- remDr$findElement("css selector","#password.b_1")$clickElement() 

remDr$findElement("css selector","#password.b_1")$sendKeysToElement(list("a")) 

remDr$findElement("css selector","td:nth-child(5) img")$clickElement()
Bharath
  • 1,600
  • 14
  • 25
  • Thank you for your help and I just tried your way. However, I still got the error when I added **$clickElement()** `Summary: ElementNotVisible Detail: An element command could not be completed because the element is not visible on the page.` – 吴浩然 Dec 15 '16 at 07:46
  • Please try my new code in the answer. I have edited that – Bharath Dec 15 '16 at 18:47