selenium在谷歌浏览器chrome上报“Cannot call method 'indexOf' of undefined”错误的解决

今天发现selenium自动测试程序在chrome上跑的时候有时会报这个错误:
Cannot call method 'indexOf' of undefined
现在发现执行以下语句的时候会报错:
selenium.waitForPageToLoad()
selenium.open()
这个错误只出现在chrome上,ie和firefox上没问题,也许safari上也会报(和chrome内核一样)。

在网上搜了一下,只找到一个地方说这个问题:
http://jira.openqa.org/browse/SRC-740

按照这个说法改了一下,就好了。现在记录如下:

1. 需要将selenium remote control更新到1.0.3
  我以前用的是selenium rc 1.0.1,需要更新到1.0.3,其中selenium-server.jar中就包含了java
  客户端,注意要用这个客户端(DefaultSelenium),而不要用selenium-java-client-driver.jar
  里的,这两个不一样。
 
2. 客户端启动时要传入"--disable-web-security"参数,如下:

	selenium = new DefaultSelenium(location, port, browser, targetPath);
	BrowserConfigurationOptions bco = new BrowserConfigurationOptions();
	selenium.start(bco.setCommandLineFlags("--disable-web-security"));


这样改了就没问题了,具体原因请参照上面的url

猜你喜欢

转载自yiyu.iteye.com/blog/670526
今日推荐