日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Java Selenium起步

發布時間:2025/4/14 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java Selenium起步 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先將錄制的腳本導出來,轉成java的格式

在Eclipse中編輯并運行test
? ? 2.1 新建一個Java project: File-New-Java Project
? ? 2.2 在上一步建好的項目名稱上點鼠標右鍵, 點擊Build Path-Add External Archives...,將下載的selenium-java-2.21.0.jar(client)和selenium-server-standalone-??2.21.0.jar(server)加進來

? ? 2.3 啟動selenium server.進入cmd,運行 "java ?-jar selenium-server-standalone-2.21.0.jar" --保證能找到改jar包。信息如下:

?

[java] view plaincopy
  • 信息:?Launching?a?standalone?server??
  • 22:16:21.484?INFO?-?Java:?Sun?Microsystems?Inc.?17.1-b03??
  • 22:16:21.500?INFO?-?OS:?Windows?XP?5.1?x86??
  • 22:16:21.515?INFO?-?v2.21.0,?with?Core?v2.21.0.?Built?from?revision?16552??
  • 22:16:21.859?INFO?-?RemoteWebDriver?instances?should?connect?to:?http://127.0.0.??
  • 1:4444/wd/hub??
  • 22:16:21.875?INFO?-?Version?Jetty/5.1.x??
  • 22:16:21.875?INFO?-?Started?HttpContext[/selenium-server/driver,/selenium-server??
  • /driver]??
  • 22:16:21.875?INFO?-?Started?HttpContext[/selenium-server,/selenium-server]??
  • 22:16:21.875?INFO?-?Started?HttpContext[/,/]??
  • 22:16:22.062?INFO?-?Started?org.openqa.jetty.jetty.servlet.ServletHandler@5d173??
  • 22:16:22.062?INFO?-?Started?HttpContext[/wd,/wd]??
  • 22:16:22.093?INFO?-?Started?SocketListener?on?0.0.0.0:4444??
  • 22:16:22.093?INFO?-?Started?org.openqa.jetty.jetty.Server@32fb4f??

  • 2.4 代碼測試

    [java] view plaincopy
  • import?com.thoughtworks.selenium.DefaultSelenium;??
  • ???
  • public?class?SeleniumDemo01??
  • {??
  • ??public?static?void?main(String[]?args)??
  • ??{??
  • ??????String?host?=?"localhost";??
  • ??????int?port?=?4444;??
  • ??????String?url?=?"http://www.baidu.com/";??
  • ??????String?browserType?=?"*firefox";??
  • ???
  • ??????String?keyWordsLocator?=?"document.getElementById('kw')";?????
  • ??????String?search?=?"document.getElementById('su')";??
  • ??????DefaultSelenium?selenium?=?new?DefaultSelenium(host,port,browserType,url);??
  • ??????selenium.start();??
  • ??????selenium.open(url);??
  • ??????selenium.type(keyWordsLocator,"java?selenium");??
  • ??????selenium.click(search);??
  • ??????selenium.waitForPageToLoad("50000");??
  • ??????selenium.stop();??
  • ???????
  • ??}??
  • }??
  • 運行結果:??
  • ????1.firefox瀏覽器期待??
  • ????2.打開百度主頁??
  • ????3.在搜索框中鍵入了"java?selenium"??
  • ????4.點擊"百度一下"按鈕??
  • ????5.等等頁面加載50s??
  • ????6.關閉瀏覽器????????????????
  • 摘自http://blog.csdn.net/test_me/article/details/7471364
  • 轉載于:https://www.cnblogs.com/yatou-de/p/4225864.html

    總結

    以上是生活随笔為你收集整理的Java Selenium起步的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。