在IE浏览器中进行自动化,首先须要安装Win32::IEAutomation这个模块,此模块至关强大,能操做浏览器的刷新,后退,前进等,因为AutoItX3.dll也嵌在里面,甚至能够操做浏览器中弹出的windows窗口web
在IEAutomation.pm的文件中,给出了使用它的例子:windows
1 use Win32::IEAutomation; 2 3 # Creating new instance of Internet Explorer 4 my $ie = Win32::IEAutomation->new( visible => 1, maximize => 1); 5 6 # Site navigation 7 $ie->gotoURL('http://www.google.com'); 8 9 # Finding hyperlinks and clicking them 10 # Using 'linktext:' option (text of the link shown on web page) 11 $ie->getLink('linktext:', "About Google")->Click; 12 # Or using 'linktext:' option with pattern matching 13 $ie->getLink('linktext:', qr/About Google/)->Click; 14 # Or using 'id:' option ( <a id=1a class=q href=......>) 15 $ie->getLink('id:', "1a")->Click; 16 17 # Finding checkbox and selecting it 18 # Using 'name:' option ( <input type = "checkbox" name = "checkme" value = "1"> ) 19 $ie->getCheckbox('name:', "checkme")->Select; 20 # Or using 'aftertext:' option (for checkbox after some text on the web page) 21 $ie->getCheckbox('aftertext:', "some text here")->Select; 22 23 # Finding text field and entering data into it 24 # Using 'name:' option ( <input type="text" name="username" .......> ) 25 $ie->getTextBox('name:', "username")->SetValue($user); 26 27 # Finding button and clicking it 28 # using 'caption:' option 29 $ie->getButton('caption:', "Google Search")->Click; 30 31 # Accessing controls under frame 32 $ie->getFrame("name:", "content")->getLink("linktext:", "All Documents")->Click; 33 34 # Nested frames 35 $ie->getFrame("name:", "first_frame")->getFrame("name:", "nested_frame"); 36 37 # Catching the popup as new window and accessing controls in it 38 my $popup = $ie->getPopupWindow("title of popup window"); 39 $popup->getButton('value:', "button_value")->Click;
例子很详尽,只贴了一部分。对元素的操做放在Element.pm这个文件,在实际使用过程当中有可能会发生找不到元素的状况,可经过更改它来实现。浏览器
若是要测360浏览器怎么办呢?简单,只要将默认浏览器改为360就能够啦。测试
控制台打印若是出现中文乱码的状况,可以使用以下代码:google
1 use encoding 'utf8',STDIN=>'utf8',STDOUT=>'gb2312';
运行起来的浏览器若是想输入中文,上面的就不能解决乱码了哦。须要对字符Encode便可,以下spa
$name = "测试"; $name2 = Encode::encode('gb2312', $name);