首页 > 代码库 > C#使用seleium实现一个自动登录器
C#使用seleium实现一个自动登录器
1.http://docs.seleniumhq.org/ 下载seleium包
2.新建一个C#项目,比如控制台,引用seleium包中的dll
using System; using System.Collections.Generic; using System.Text; using OpenQA.Selenium; using OpenQA.Selenium.IE; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.UI; using System.IO; namespace WebLogin { class Program { static void Main(string[] args) { var path = Path.Combine(Environment.CurrentDirectory); IWebDriver driver = new ChromeDriver(path); driver.Navigate().GoToUrl("http://www.***.com"); var txtusername =driver.FindElement(By.Id("username")); txtusername.SendKeys("****"); var txtpassword = driver.FindElement(By.Id("password")); txtpassword.SendKeys("*****"); var submit = driver.FindElement(By.Name("Submit")); submit.Click(); } } }
亲测Chrome下的seleium没有问题,但是IE的话现在对IE11的版本支持还不太合适,我自己就遇到了模拟点击按钮时有时没有反应。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。