在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);