locked
driver.FindElement要如何自動開啟下圖的選擇檔案? RRS feed

  • 問題

  • 1.請詳列開發環境版本與語系。
    •Visual Studio Community 2019 繁體中文版
    •編譯器語系:C#
    •作業系統:Windows 10 Professional 64位元
    •作業系統語系:繁體中文版

    2.請描述預期成果。
    •更新時driver.FindElement要如何自動開啟下圖的選擇檔案?

    using Excel = Microsoft.Office.Interop.Excel;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Edge;
    using OpenQA.Selenium.Support.UI;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                
                richTextBox1.Text = "\n\n\n";
                string[] textLines = richTextBox1.Lines;
                textLines[0] = "開始時間:" + DateTime.Now.ToShortTimeString();
                richTextBox1.Lines = textLines;
                var edgeDriverService = EdgeDriverService.CreateDefaultService();
                //edgeDriverService.HideCommandPromptWindow = true;
                EdgeOptions options = new EdgeOptions();
                var driver = new EdgeDriver(edgeDriverService, options);
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3000));                                                                                                                                      
                wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(360);
                //driver.Manage().Window.Size = new Size(1000, 300);
                driver.Navigate().GoToUrl("https://172.18.2.1");                                                                                                                                                               //設備IP位置
                driver.FindElement(By.Id("details-button")).Click();                                                                                                                                                           //其它資訊
                driver.FindElement(By.Id("proceed-link")).Click();                                                                                                                                                             //繼續瀏覽網頁(不建議)
                driver.FindElement(By.Id("username")).SendKeys("admin");                                                                                                                                                       //帳號
                driver.FindElement(By.Id("secretkey")).SendKeys("nccadmin");                                                                                                                                                   //密碼
                driver.FindElement(By.Id("login_button")).Click();                                                                                                                                                             //登入(到此步驟正常)
                //driver.FindElement(By.ClassName("submenu-label")).Click();                                                                                                                                                   //(請勿刪除)會開啟FortiViewv選單
                driver.Navigate().GoToUrl("https://172.18.2.1/ng/page/system/status/status");
                driver.Navigate().GoToUrl("https://172.18.2.1/ng/system/fortiguard");
                driver.FindElement(By.XPath("//*[@id='main-container']/div[1]/section/table/tbody/tr[2]/td[3]")).Click();                                                                                                      //IPS & 應用程式控制 上傳Package                                                                                                                                                                 
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
        }
    }




    • 已編輯 fanchiangkun 2021年7月29日 上午 06:08 更新內容
    2021年7月29日 上午 01:51

解答

所有回覆