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

      

  • 相关阅读:
    40个Java集合面试问题和答案
    jsp九大内置对象:request、response、session、application、out、page、pageContext、config、exception
    JAVA多线程和并发基础面试问答
    线程的五大状态
    人物与动物快速抠图技巧
    实时监听数据库变化
    inter jion与WITH (NOLOCK) 排他锁(脏读)
    Win定时任务未正常运行的bug(win Server2019)
    HttpWebRequest与HttpWebResponse的关系
    A5M2 sql自动换行快捷键
  • 原文地址:https://www.cnblogs.com/coolyylu/p/8327836.html
Copyright © 2011-2022 走看看