selenium實現瀏覽器截圖,拖拽頁面元素

2021-07-10 09:54:28 字數 963 閱讀 3445

1.實現瀏覽器截圖

//呼叫getscreenshotas方法把當前瀏覽器開啟的頁面進行截圖,儲存到file物件中

file scrfile = ((takesscreenshot)driver).getscreenshotas(outputtype.file);

try catch (ioexception e)

2.殺死瀏覽器程序

windowsutils.trytokillbyname("firefox.exe");

3.檢查頁面元素文字是否出現

webelement text = driver.findelement(by.xpath("//p[1]"));
//獲取p標籤的文字內容

string contenttext = text.gettext();

assert.assertequals("《光榮之路》這個電影真的很棒!", contenttext);

assert.asserttrue(contenttext.contains("光榮之路"));

assert.asserttrue(contenttext.startswith("《光榮"));

assert.asserttrue(contenttext.endswith("很棒!"));

4.拖拽頁面可以移動的元素

//尋找可以被拖拽的頁面物件

webelement draggable = driver.findelement(by.id("draggable"));

//向下拖動是個畫素,共拖動5次

for (int i = 0; i < 5; i++)

for (int i = 0; i < 5; i++)

瀏覽器長截圖

利用chrome瀏覽的開發者工具,完美實現網頁全屏截圖,不需要安裝任何外掛程式,大家快來試試吧。ctrl shift i f12 ctrl shift p 輸入 screen 選擇不用的方式擷取 整個網頁 capture full size screenshot 節點網頁 capture node ...

IE瀏覽器整頁截圖程式

最近專案中涉及到瀏覽器整頁截圖的功能,有點複雜,研究了一天,終於在ie瀏覽器下實現,至於其他瀏覽器,以後再研究。所謂整頁截圖,就是說把整個頁面全部截進去,包括通過滾動才能看到的部分。方法是好的,悲催的是,沒有乙個 是能正常執行的,相信很多人都有同感!沒辦法,自己動手,豐衣足食。我需要用.net來實現...

IE瀏覽器整頁截圖程式(二)

實現步驟如下 1 新建乙個form應用程式,在窗體上新增乙個panel,假設name為panel1,設定 panel1.autoscroll true。2 在panel1中放置乙個webbrowser控制項,假設name為webbrowser1,設定 webbrowser1.scripterrors...