Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to click the button from specific website opened on a specific browser, my inputs will be Browser variable and the element name(like button ID or class), how can I focus to the exact browser window?

What I have tried:

I tried searching but I got like creating new process only

string targetURL = @"http://pedroliska.com";
System.Diagnostics.Process.Start(targetURL);


let me know if any ideas...
Posted
Updated 23-Oct-18 1:52am
Comments
F-ES Sitecore 23-Oct-18 6:35am    
That code is only appears to work because you are testing on your local machine so server and client are the same. When you deploy your app to a remote server the Process.Start runs on the server, not the client. You can't start tasks on the client for obvious security reasons.
#realJSOP 23-Oct-18 7:24am    
Obvious to some, maybe...
Richard Deeming 23-Oct-18 8:01am    
I know it's a common mistake, but are we sure that the OP is writing an ASP.NET application, and not trying to automate a browser from a desktop application?

You know what they say about "assume". :)
F-ES Sitecore 23-Oct-18 9:13am    
Not 100% sure, but 99% :)

1 solution

C# code runs on the server, not the client, and cannot cause any applications at all to run on a client machine. The only code which runs on the client is Javascript, and that can't directly start an application either for security reasons.

So when you use Process.Start, that runs on the server and opens the server default app (normally a browser) to open the URL. You cannot specify which browser is opened if more than one is installed without specifically instructing Process which application by giving it's full path, and pass the URL as an argument.
But even if you did that, the client would not be able to see it or interact in any way with the browser that opened.

It "works" in development because the client and the server are the same physical machine, in exactly the same way that MessageBox will "work" in development - but will fail in production because the displayed box or app is thousands of miles from teh client you are trying to display it to!

All you can do is add an href link to the URL to the page the browser displays and let it open in the user's current browser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900