zoukankan      html  css  js  c++  java
  • selenium 百度登陆

    using System;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Firefox;//引用命名空间
    using System.IO;

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    namespace Selenium2
    {
    class Program
    {
    static void Main(string[] args)
    {
    IWebDriver driver = new FirefoxDriver();
    INavigation navigation = driver.Navigate();
    navigation.GoToUrl("http://baidu.com");
    //IWebElement baiduTextBox = driver.FindElement(By.Id("kw"));
    //baiduTextBox.SendKeys("找到文本框");
    IWebElement baiduLogin = driver.FindElement(By.LinkText("登录"));
    baiduLogin.Click();
    System.Threading.Thread.Sleep(3000);
    //IWebElement baiduLogin = driver.FindElement(By.XPath("//input[@id='kw']"));
    IWebElement userName = driver.FindElement(By.Name("userName"));
    IWebElement passWord = driver.FindElement(By.Name("password"));
    userName.SendKeys("百度用户名");
    passWord.SendKeys("密码");
    passWord.Submit();
    System.Threading.Thread.Sleep(3000);
    //IWebElement getText = driver.FindElement(By.XPath("//span[@class='user-name']"));
    IWebElement getText = driver.FindElement(By.XPath("//div[@id='u_sp']"));//mouseMove到那个元素看看 C#
    string outPut = getText.Text;
    //baiduLogin.SendKeys("爱你");
    StreamWriter f = new StreamWriter(@"J:vs2010_lin_projectsSelenium2hellolin.txt", false);
    f.WriteLine(outPut);
    f.Close();
    Console.WriteLine(outPut);
    Console.ReadKey();
    }
    }
    }

  • 相关阅读:
    php(ThinkPHP)实现微信小程序的登录过程
    路由器OpenWrt如何脱机(离线)下载BT文件
    OPENWRT X86 安装使用教程 (未完成)
    openwrt l7过滤qos配置
    Ushare应用
    脱机BT transmission
    js实现编码,解码
    波尔远程控制软件与网络人远程控制软件大比拼
    baike并行计算概念
    开机启动tomcat
  • 原文地址:https://www.cnblogs.com/alex-13/p/4736704.html
Copyright © 2011-2022 走看看