zoukankan      html  css  js  c++  java
  • selenium上传文件

    using System;
    using System.Collections.Generic;
    using System.Text;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Remote;
    using System.Runtime.InteropServices;
    
    namespace eip_auto_test
    {
        
        class BatchCreateProductBomWeight
        {
            [DllImport("user32.dll")]
            public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
    
            public static void Test()
            {
                ChromeOptions option = new ChromeOptions();
                option.AddArguments("disable-infobars");
    
                ChromeDriver cd = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, option);
    
                cd.SwitchTo().Window(cd.WindowHandles[cd.WindowHandles.Count - 1]).Manage().Window.Maximize();
                cd.Navigate().GoToUrl(Common.server_url);
                cd.FindElementById("txtName").SendKeys("test");
                cd.FindElementById("txtPassword").SendKeys("123");
                cd.FindElementById("BtnLogin").Click();
    
                cd.FindElementByLinkText("Data").Click();
    
                cd.FindElementByLinkText("Customer").Click();
    
                cd.FindElementByLinkText("Weight List").Click();
    
                IWebElement iframe = cd.FindElement(By.Id("main"));
                cd.SwitchTo().Frame(iframe);
    
    
                IWebElement element = cd.FindElement(By.Id("fileBrowe"));            
                IWebElement file = cd.FindElement(By.Id("btnBrowse"));            
                file.Click();
    
    
                Common.Delay(500);
                keybd_event(27, 0, 0, 0);            
                keybd_event(27, 0, 2, 0);
    
    
                element.SendKeys(@"C:mydocCustom.xlsx");
                cd.ExecuteScript("$('#fileBrowe').change()");
    
                cd.FindElement(By.Id("btnUpload")).Click();
                
    
    
                Console.ReadLine();
                cd.Quit();
            }
    
          
        }
    }
    

      

    循环测试的版本

         static void Main(string[] args)
            {
                for(int zz=1;zz<20;zz++)
                    BatchCreateProductBomWeight.Test();
            }
    

      

    using System;
    using System.Collections.Generic;
    using System.Text;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Remote;
    using System.Runtime.InteropServices;
    
    namespace eip_auto_test
    {
        
        class BatchCreateProductBomWeight
        {
            [DllImport("user32.dll")]
            public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
    
            public static void Test()
            {
                ChromeOptions option = new ChromeOptions();
                option.AddArguments("disable-infobars");
    
                ChromeDriver cd = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, option);
    
                cd.SwitchTo().Window(cd.WindowHandles[cd.WindowHandles.Count - 1]).Manage().Window.Maximize();
                cd.Navigate().GoToUrl(Common.server_url);
                cd.FindElementById("txtName").SendKeys("test");
                cd.FindElementById("txtPassword").SendKeys("123");
                cd.FindElementById("BtnLogin").Click();
    
                cd.FindElementByLinkText("Data").Click();
    
                cd.FindElementByLinkText("Customer").Click();
    
                cd.FindElementByLinkText("Weight List").Click();
    
                IWebElement iframe = cd.FindElement(By.Id("main"));
                cd.SwitchTo().Frame(iframe);
    
    
                IWebElement element = cd.FindElement(By.Id("fileBrowe"));            
                IWebElement file = cd.FindElement(By.Id("btnBrowse"));            
                file.Click();
    
    
                Common.Delay(500);
                keybd_event(27, 0, 0, 0);            
                keybd_event(27, 0, 2, 0);
    
    
                element.SendKeys(@"c:mydoccustomer.xlsx");
                cd.ExecuteScript("$('#fileBrowe').change()");
    
                cd.FindElement(By.Id("btnUpload")).Click();
    
    
                IWebElement state = cd.FindElement(By.Id("myState0"));
    
                Console.WriteLine(state.Text);
    
                while (state.Text != "完成")
                {
                    Common.Delay(1000);
                }
    
                Common.Delay(2000);
                cd.Quit();
            }
    
          
        }
    }
    

      

  • 相关阅读:
    Zookeeper基本使用(转)
    mongon命令(转)
    openstack之cinder
    raw格式转换成qcow2格式
    calico网络
    route命令使用
    guestfish修改镜像内容
    基于etcd插件的CoreDNS动态域名添加
    dns记录类型(转)
    C语言 格式化输出--%m.n
  • 原文地址:https://www.cnblogs.com/coolyylu/p/8327836.html
Copyright © 2011-2022 走看看