selenium rc学习笔记

今天在公司进一步学习了selenium-rc 可是在公司运行正常的最简单的代码,在家里居然报错了 代码如下:
@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*googlechrome ", "http://www.baidu.com/");
		selenium.start();
	}
后经一番折腾改为:
@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*googlechrome C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "http://www.headin.cn/");
		selenium.start();
	}

  具体什么原因在成的呢,进一步解密中……

另外报错代码如下:


java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: java.lang.RuntimeException: Google Chrome could not be found in the path! Please add the directory containing ''chrome.exe' or 'google-chrome'' to your PATH environment variable, or explicitly specify a path to Google Chrome like this: *googlechromec:\blah\chrome.exe at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89) at example.SeleniumTest1.setUp(SeleniumTest1.java:15) at junit.framework.TestCase.runBare(TestCase.java:132) at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:243) at junit.framework.TestSuite.run(TestSuite.java:238) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: java.lang.RuntimeException: Google Chrome could not be found in the path! Please add the directory containing ''chrome.exe' or 'google-chrome'' to your PATH environment variable, or explicitly specify a path to Google Chrome like this: *googlechromec:\blah\chrome.exe at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97) at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91) at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262) at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:223) at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:81) ... 16 more

  

转载于:https://www.cnblogs.com/aimeih/archive/2012/04/18/2456188.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以帮你输出一篇Selenium学习笔记。以下是一份简单的学习笔记供参考: Selenium学习笔记 Selenium是一款用于自动化Web应用程序测试的强大工具。它提供了一组丰富的API,可以与各种编程语言(如PythonJava、C#等)结合使用,以实现Web应用程序的自动化测试。 1. 安装和配置 首先,你需要安装Selenium库。如果你使用Python,可以使用以下命令安装: ``` pip install selenium ``` 安装完成后,你还需要下载并配置相应的浏览器驱动程序。Selenium支持各种浏览器,如Chrome、Firefox、Safari等。你可以在Selenium官方网站上找到相应的驱动程序下载链接。 2. 基本操作 Selenium提供了一系列方法来模拟用户在浏览器中的操作,如打开URL、点击元素、输入文本等。以下是一些常用的基本操作示例: - 打开浏览器并访问URL: ```python from selenium import webdriver driver = webdriver.Chrome() # 使用Chrome浏览器驱动 driver.get("https://www.example.com") # 打开指定URL ``` - 查找元素并操作: ```python element = driver.find_element_by_id("element_id") # 根据元素ID查找 element.click() # 点击元素 input_element = driver.find_element_by_name("input_name") # 根据元素名称查找 input_element.send_keys("Hello, World!") # 输入文本 ``` - 执行JavaScript代码: ```python driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # 滚动到页面底部 ``` 3. 高级操作 Selenium还提供了一些高级操作,如处理弹窗、切换窗口、等待元素加载等。以下是一些常用的高级操作示例: - 处理弹窗: ```python alert = driver.switch_to.alert # 切换到弹窗 alert.accept() # 接受弹窗 confirm = driver.switch_to.alert # 切换到确认框 confirm.dismiss() # 取消确认框 ``` - 切换窗口: ```python window_handles = driver.window_handles # 获取所有窗口句柄 driver.switch_to.window(window_handles[-1]) # 切换到最后一个窗口 ``` - 等待元素加载: ```python from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "element_id")) ) ``` 4. 测试框架 Selenium还可以与测试框架(如Pytest、JUnit等)结合使用,以便更好地组织和管理测试用例。你可以使用测试框架提供的断言方法来验证测试结果。 ```python import pytest def test_example(): driver = webdriver.Chrome() driver.get("https://www.example.com") assert "Example Domain" in driver.title # 断言页面标题包含指定文本 driver.quit() ``` 以上是一份简单的Selenium学习笔记,希望对你有所帮助。当然,Selenium还有很多其他功能和用法,你可以进一步深入学习和探索。祝你学习愉快!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值