如何使用Powershell在Microsoft Edge上选择链接?

时间:2019-05-28 15:30:48

标签: powershell microsoft-edge

我正在编写一个PowerShell脚本,该脚本要求使用Microsoft Edge(管理员阻止了Internet Explorer),并且需要单击网站上的链接。我想知道实现此目标的最佳方法是什么?

我尝试开始使用启动Microsoft Edge进程,但是打开后它不允许我与网站进行交互。

启动microsoft-edge:“ https://google.com

1 个答案:

答案 0 :(得分:0)

我同意@ kuzimoto提出的建议,即您将无法使用Powershall命令单击链接。

您可以尝试从下面的链接下载硒Web驱动程序。

Download Selenium Web driver

这是打开特定网页并使用Selenium C#代码单击页面上链接的示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Support.UI;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            IWebDriver driver = new EdgeDriver();

            driver.Navigate().GoToUrl(@"C:\Users\panchals\Desktop\tests\login_form.html");

            try
            {

                driver.FindElement(By.Name("demo_link")).Click();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();

            driver.Quit();
            driver.Close();

        }
    }
}

HTML页面代码:

<!DOCTYPE html>
<html>
<head>
    <title>Login Form</title>
<script>
function abc()
{
alert("Logged in successfully.");
}
function xyz()
{
alert("Link clicked by selenium code....");
}
</script>
</head>
<body>

<form action="">


  <div class="container">
    <label for="uname"><b>Username :</b></label>
    <input type="text" placeholder="Enter Username" name="uname"><br>

    <label for="psw"><b>Password : </b></label>
    <input type="password" placeholder="Enter Password" name="psw"><br>

    <button type="submit" name="signIn"  onclick="abc()">Login</button><br>
   <a href="" id="demo_link" name="demo_link" onclick="xyz()">Click me.......</a>
</form>

</body>
</html>

MS Edge中的输出:

enter image description here