如何解决“访问属性'文档'的权限被拒绝”?

软件测试 硒2 C#
2022-01-13 13:47:58

我在stackoverflow.com上发布了它。有人建议我把它贴在这里...

在尝试使用 selenium rc 进行自动化测试时,我遇到了这个问题。我只是按照教程中的步骤进行操作。这是代码(与教程相同):

[TestFixture]
public class SeleniumTest
{
    private ISelenium selenium;
    private StringBuilder verificationErrors;

    [SetUp]
    public void SetupTest()
    {
        selenium = new DefaultSelenium("localhost", 4444, @"*custom D:\Program Files (x86)\Firefox 4\firefox.exe", "http://www.google.com/");
        selenium.Start();
        verificationErrors = new StringBuilder();
    }

    [TearDown]
    public void TeardownTest()
    {
        try
        {
            selenium.Stop();
        }
        catch (Exception)
        {
            // Ignore errors if unable to close the browser
        }
        Assert.AreEqual("", verificationErrors.ToString());
    }

    [Test]
    public void TheGoogleTest()
    {
        selenium.Open("/");
        selenium.Type("lst-ib", "selenium");
        try
        {
            Assert.IsTrue(selenium.IsTextPresent("Selenium - Web Browser Automation"));
        }
        catch (AssertionException e)
        {
            verificationErrors.Append(e.Message);
        }
    }
}

当我运行测试时,我的 firefox-5 浏览器会弹出,并且 url 看起来像这样: http ://www.google.com/selenium-server/core/RemoteRunner.html?sessionId=507c2d6ec7214587984f0f86148e9ff5&multiWindow=true&baseUrl=http%3A% 2F%2Fwww.google.com%2F&debugMode=false

我认为 url 应该是http://localhost:4444并更改了 url(保留其余部分)。现在打开了一个硒页面(RemoteRunner.html )(右侧有命令)。然后它打开谷歌页面,但之后什么也没有。nunit向我展示了测试用例失败,并说明了原因:Permission denied to access property 'document'

任何想法?提前致谢。

1个回答

您可以将硒对象实例化为吗?

selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");

这里*chrome指的是firefox浏览器,对java脚本安全限制有提升的安全权限。