How to open a html file available in local machine in selenium grid-node?

306 views
Skip to first unread message

Sivaprakash R

unread,
Aug 7, 2018, 1:02:07 PM8/7/18
to Selenium Users

I have a html file in my local machine.When running my selenium-java code locally through eclipse, I can access the html file through the code mentioned below.

File file = new File(url);

driver.get("file:///" + file.getAbsolutePath());

If I run the code through selenium grid, Registered node doesn't pick up the html file path to be opened in chrome since the absolute path points to the local machine.

Is there any solution available to open the locally available html file through selenium grid-node?

Krishnan Mahadevan

unread,
Aug 8, 2018, 12:15:19 AM8/8/18
to seleniu...@googlegroups.com

First option is:

You need to follow the below steps:

 

  1. Build a servlet which when invoked with a HTTP POST receives the file as an attachment and saves it locally and returns back the path where the file was saved.
  2. Inject the servlet built in step (1) into the node. To learn how to do this, refer to my blog here
  3. Create a new RemoteWebDriver instance.
  4. Use a mechanism as described in this blog post of mine to find out the IP and Port to which your test was routed to (or) use a library such as talk2grid which I built to get this information.
  5. Using the IP and Port obtained in (4) invoke the servlet with the html file as an attachment.
  6. Now open up the url just as you would do, but with the path obtained from (1)

 

The other option is:

Use Javascript to create the page dynamically and then work with it. You can refer to this stackoverflow post that talks about how to add a div to a page and extrapolate that information to weave in the entire page using a series of calls to driver.executeScript()

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/13442902-cfd6-4008-90b2-acea9636208c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sivaprakash R

unread,
Aug 9, 2018, 2:00:13 AM8/9/18
to Selenium Users
Thank you for the response.

Another Query, what does localFileDetector does in selenium?

will it be of any use for my case?

Regards,
Sivaprakash Rudhrasamy 

⇜Krishnan Mahadevan⇝

unread,
Aug 9, 2018, 2:02:09 AM8/9/18
to seleniu...@googlegroups.com
It lets you interest with an input type=file element. 

It's not useful for you in this case. 


For more options, visit https://groups.google.com/d/optout.
--
Reply all
Reply to author
Forward
0 new messages