如何在打开多个浏览器时通过浏览器变量关注所需的浏览器? [英] How to focus on required browser by passing browser variable when multiple browsers are opened?

查看:96
本文介绍了如何在打开多个浏览器时通过浏览器变量关注所需的浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想点击特定浏览器上打开的特定网站上的按钮,我的输入将是浏览器变量和元素名称(如按钮ID或类),我如何专注于确切的浏览器窗口?



我尝试了什么:



我试过搜索但我想创建新流程只有



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...

推荐答案

C#代码在服务器上运行,而不是在客户端上运行,并且不能使任何应用程序在客户端计算机上运行。在客户端上运行的唯一代码是Javascript,并且出于安全原因无法直接启动应用程序。



因此当您使用Process.Start时,在服务器上运行并打开服务器默认应用程序(通常是浏览器)以打开URL。如果安装了多个浏览器而没有专门指示通过提供完整路径来处理哪个应用程序,并且将URL作为参数传递,则无法指定打开哪个浏览器。

但即使你这样做,客户端也是如此将无法看到它或以任何方式与打开的浏览器进行交互。



它在开发中有效,因为客户端和服务器是相同的物理机器,与MessageBox在开发中工作的方式完全相同 - 但是在生产中会失败,因为显示的盒子或应用程序距离您试图显示它的客户端数千英里!



您所能做的就是添加一个 href 链接到浏览器显示的页面的URL并让它在用户当前的浏览器中打开。
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.


这篇关于如何在打开多个浏览器时通过浏览器变量关注所需的浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆