Button Selenium RC:如何单击使用onclick window.location的按钮?

Button Selenium RC:如何单击使用onclick window.location的按钮?,button,safari,selenium,phpunit,window.location,Button,Safari,Selenium,Phpunit,Window.location,我有一个按钮(在表单外部),它使用调用window.location的onclick属性将用户重定向到另一个页面。这次我无法更改HTML。我正在使用Safari4进行测试。如何单击使用onclick属性和window.location使用Safari 4和Selenium RC PHPUnit扩展重定向的按钮 这是我的HTML: <input type="button" onclick="window.location='/registrations/new'" value="Start

我有一个按钮(在表单外部),它使用调用
window.location
onclick
属性将用户重定向到另一个页面。这次我无法更改HTML。我正在使用Safari4进行测试。如何单击使用
onclick
属性和
window.location
使用Safari 4和Selenium RC PHPUnit扩展重定向的按钮

这是我的HTML:

<input type="button" onclick="window.location='/registrations/new'" value="Start a new registration" id="create">

更新:或者,我正在考虑做一些事情,断言在
窗口中指定了一个位置。location='
,存储该位置,并使用该位置调用
open()
命令。不确定这是否是一种可接受的测试方法。

这应该可以工作,但是您也可以尝试使用
firevent
命令触发click事件

selenium.fireEvent("id=create", "click");

我们决定扩展默认的
clickAndWait()
功能,如果按钮有
onclick=“window.location=”/something“;”


当你点击它时会发生什么,标准方式?当你手动点击它时,它工作正常。但当尝试使用Selenium RC单击它时,它不会重定向。当您在另一个浏览器中运行测试时会发生什么情况?我已经在Firefox中成功地测试过了,这只是Safari的问题吗?
/**
 * Extends original clickAndWait() functionality to provide the ability to click buttons that use window.location to redirect users
 * @param $locator
 */
public function clickAndWait($locator)
{
    $this->assertElementPresent($locator);
    $hasOnclickAttribute = $this->getEval('this.browserbot.findElement("' . $locator . '").hasAttribute("onclick")');
    if ($hasOnclickAttribute === 'true') {
        $onclickValue = $this->getAttribute("$locator@onclick");
        if (strpos($onclickValue, "window.location=") !== false) {

            // Clean up the location
            $temp = explode("=" , $onclickValue);               
            $location = trim($temp[1], "';");               
            $location = trim($location, '"');

            return $this->openAndWait($location);
        }
    }
    return parent::clickAndWait($locator);
}