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();
            }
    
          
        }
    }
    

      

  • 相关阅读:
    如何看待和选择基础设施软件
    target vs currentTarget, clientWidth vs offsetWidth
    undefined
    C# and android and socket
    hdu 4781 Assignment For Princess (2013ACMICPC 成都站 A)
    [置顶] Jquery中DOM操作(详细)
    hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)
    android开发教程(八)——环境搭建之java-ndk
    cloudstack4.2+xenserver6.0.2 详细配置攻略
    11道php面试题
  • 原文地址:https://www.cnblogs.com/coolyylu/p/8327836.html
Copyright © 2011-2022 走看看