|
本帖最后由 愚人 于 2012-4-20 15:20 编辑
selenium怎样获取动态图片验证码?
在点开页面后,点用户名和密码后需要图片验证码?
我自动转换为C#后不知道要怎么写来验证验证码了
源码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Selenium;
using System.Threading;
namespace TestFor2012420
{
public partial class Form1 : Form
{
private ISelenium selenium;
private StringBuilder verificationErrors;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://mydiy.pconline.com.cn/");
selenium.Start();
verificationErrors = new StringBuilder();
selenium.Open("/");
selenium.Click("xpath=(//a[contains(text(),'选用')])[6]");
selenium.Click("//span[@type='1']");
selenium.Type("xpath=(//input[@name='product_query'])[2]", "华硕");
selenium.Click("xpath=(//input[@name='search'])[2]");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[2]");
Thread.Sleep(3000);
selenium.Click("//span[@type='2']");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[3]");
Thread.Sleep(3000);
selenium.Type("id=num_2", "2");
Thread.Sleep(3000);
selenium.Click("//span[@type='3']");
Thread.Sleep(3000);
selenium.Click("link=2");
Thread.Sleep(3000);
selenium.Click("link=3");
Thread.Sleep(3000);
selenium.Click("link=选用");
Thread.Sleep(3000);
selenium.Click("//span[@type='4']");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[5]");
Thread.Sleep(3000);
selenium.Click("//span[@type='5']");
Thread.Sleep(3000);
selenium.Click("link=2");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[5]");
Thread.Sleep(3000);
selenium.Click("//span[@type='6']");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[7]");
Thread.Sleep(3000);
selenium.Click("//span[@type='7']");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[7]");
Thread.Sleep(3000);
selenium.Click("//span[@type='8']");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(5000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[4]");
Thread.Sleep(3000);
selenium.Click("//span[@type='9']");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[4]");
Thread.Sleep(3000);
selenium.Click("//span[@type='10']");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[4]");
Thread.Sleep(3000);
selenium.Click("//span[@type='11']");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("link=下一页");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[4]");
Thread.Sleep(3000);
selenium.Click("//span[@type='12']");
Thread.Sleep(3000);
selenium.Click("//span[@type='15']");
Thread.Sleep(3000);
selenium.Click("xpath=(//a[contains(text(),'选用')])[2]");
Thread.Sleep(3000);
selenium.Select("name=DiyType", "label=专业设计方案");
Thread.Sleep(3000);
selenium.Type("id=DiyTitle", "测试");
Thread.Sleep(3000);
selenium.Type("id=DiyComment", "此程序用于测试");
}
}
}
该怎么解决呢?说详细一点。。谢谢大家了 |
|