标签: webdriver

Selenium 2.0b3 IE WebDriver,点击不激活

在IE9中使用IE驱动程序时,偶尔Click方法只会选择一个按钮,它不会执行Click()的操作.请注意,这只会偶尔发生,所以我不认为这是代码问题.在Firefox4上使用Firefox驱动程序没有问题.我也有一个问题,偶尔也没有找到元素,但只在IE中再次发现,而不是Firefox.

if (Driver.FindElement(By.Name("username")) == null) {
    //sometimes gets here in IE, never gets here in Firefox
}
Driver.FindElement(By.Name("username")).SendKeys(username);
Driver.FindElement(By.Name("surname")).SendKeys(surname);
Driver.FindElement(By.Name("firstname")).SendKeys(firstname);
string url = Driver.Url;
Driver.FindElement(By.Name("cmd")).Click();
if (Driver.Url == url) {
    //if the page didnt change, click the link again
    Driver.FindElement(By.Name("cmd")).Click();
}
Run Code Online (Sandbox Code Playgroud)

我已经看到了类似的问题(http://stackoverflow.com/questions/4737205/selenium-webdriver-ie-button-issue),但我没有动态生成的ID.

webdriver internet-explorer-9 selenium-webdriver

41
推荐指数
5
解决办法
5万
查看次数

在selenium中定位WebElements的子节点

我正在使用selenium来测试我的Web应用程序,我可以使用成功找到标签By.xpath.但是现在我需要在该节点中找到子节点.

例:

<div id="a">
    <div>
        <span />
        <input />
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我可以:

WebElement divA = driver.findElement( By.xpath( "//div[@id='a']" ) )
Run Code Online (Sandbox Code Playgroud)

但现在我需要找到输入,所以我可以这样做:

driver.findElement( By.xpath( "//div[@id='a']//input" ) )
Run Code Online (Sandbox Code Playgroud)

但是在代码中我只有divA,而不是它的xpath ...我想做这样的事情:

WebElement input = driver.findElement( divA, By.xpath( "//input" ) );
Run Code Online (Sandbox Code Playgroud)

但是这样的功能不存在.我能这样做吗?

顺便说一句:有时候我需要找到一个<div>具有某种后代节点的东西.我怎样才能在xpath中询问"包含带有文本'hello world'的跨度的div-tag"?

java selenium xpath webdriver

41
推荐指数
2
解决办法
11万
查看次数

如何使用Selenium WebDriver处理Windows文件上传?

我在Stackoverflow上使用Selenium WebDriver看到了很多关于文件上传的问题和解决方案.但是没有一个适用于以下场景.

有人给出了如下解决方案

// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
Run Code Online (Sandbox Code Playgroud)

但我还是找不到窗口句柄我该如何处理?

截图

我正在寻找上述方案的解决方案

请检查以下任何网站

http://www.uploadify.com/demos/
http://www.zamzar.com/
Run Code Online (Sandbox Code Playgroud)

java selenium file-upload webdriver selenium-webdriver

41
推荐指数
3
解决办法
13万
查看次数

如何使用Selenium WebDriver和java从下拉列表中选择项目?

如何使用带有Java的Selenium WebDriver从性别下拉列表中选择项目(例如男性,女性)?

我试过这个

WebElement select = driver.findElement(By.id("gender"));
List<WebElement> options = select.findElements(By.tagName("Male"));
for (WebElement option : options) {
    if("Germany".equals(option.getText()))
        option.click();   
}
Run Code Online (Sandbox Code Playgroud)

我上面的代码不起作用.

java selenium webdriver selenium-webdriver

41
推荐指数
4
解决办法
30万
查看次数

Selenium WebDriver:使用XPath单击SVG中的元素

我有一个带有几个圆形和矩形元素的SVG对象.使用webdriver,我可以单击主svg对象,但不能单击其中的任何元素.问题似乎只是点击(或任何鼠标交互),因为我可以使用getAttribute()返回宽度,ID,x/y,文本等的值,以及它下面的任何内容.

以下是HTML的示例:

    <div id="canvas">
        <svg height="840" version="1.1" width="757" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative;">
            <image x="0" y="0" width="757" height="840" preserveAspectRatio="none">
            <circle cx="272.34" cy="132.14">
            <rect x="241.47" y="139.23">
            <text style="text-anchor: middle; x="272.47" y="144.11">
        </svg>
    </div>
Run Code Online (Sandbox Code Playgroud)

并且WebDriver尝试右键单击矩形元素(并失败)的示例:

    WebElement mapObject = driver.findElement(By.xpath("//*[name()='svg']/*[name()='rect']"));
    Actions builder = new Actions(driver);
    builder.contextClick(mapObject).perform();
Run Code Online (Sandbox Code Playgroud)

但这可以工作并返回一个值:

    driver.findElement(By.xpath("//*[name()='svg']/*[name()='rect']")).getAttribute("x");    
Run Code Online (Sandbox Code Playgroud)

当WebDriver出错时,通常是这样的:

    org.openqa.selenium.WebDriverException: '[JavaScript Error: "a.scrollIntoView is not a function" {file: "file:///var/folders/sm/jngvd6s97ldb916b7h25d57r0000gn/T/anonymous490577185394048506webdriver-profile/extensions/fxdriver@googlecode.com/components/synthetic_mouse.js" line: 8544}]' when calling method: [wdIMouse::move]
Run Code Online (Sandbox Code Playgroud)

我花了一些时间研究这个问题,它似乎是Selenium和SVG的一个常见问题,但是我想知道是否有解决方法.我发现的唯一解决方案是与SVG本身进行交互,我已经可以做了.

我正在使用Selenium 2.28(并尝试使用2.29)w/Java + Firefox 17.

任何想法都非常感激.

java firefox selenium xpath webdriver

41
推荐指数
3
解决办法
5万
查看次数

为什么我们使用WebDriver而不是Selenium IDE?

为什么我们不能在Selenium IDE中记录所有测试用例,将其导出到Java/WebDriver并使用Eclipse在WebDriver中运行它?

我需要一个明确的解释,因为我在使用WebDriver时非常困惑!

任何人都可以解释为什么IDE记录的脚本在WebDriver中失败了吗?

selenium webdriver selenium-ide selenium-webdriver

41
推荐指数
3
解决办法
5万
查看次数

如何使用webdriver获取元素的所有后代?

有这个元素有子元素,那些子元素又有子元素等等.我想得到作为元素后代的所有元素.谢谢.

java collections selenium webdriver

40
推荐指数
2
解决办法
8万
查看次数

如何使用selenium java webdriver选择复选框?

如何使用id/xpath检查复选框.有没有类似于selecttext by selecttext的方法.

通过给出所有其他相关问题的示例,我找不到一个正确的解决方案,以简洁的方式工作,通过几行或方法我可以检查chekbox或单选按钮.

任何帮助,将不胜感激.

HTML示例部分如下:

<tbody> 
<tr> 
    <td> 
        <span class="120927"> 
        <input id="ctl00_CM_ctl01_chkOptions_0" type="checkbox" name="ctl00$CM$ctl01$chkOptions$0"/> 
        <label for="ctl00_CM_ctl01_chkOptions_0">housingmoves</label> 
        </span> 
    </td> 
</tr> 
<tr>
    <td>
        <span class="120928"> 
        <input id="ctl00_CM_ctl01_chkOptions_1" type="checkbox" name="ctl00$CM$ctl01$chkOptions$1"/> 
        <label for="ctl00_CM_ctl01_chkOptions_1">Seaside & Country Homes</label> 
        </span> 
    </td> 
</tr> 
</tbody> 
Run Code Online (Sandbox Code Playgroud)

selenium xpath webdriver selenium-webdriver

40
推荐指数
5
解决办法
24万
查看次数

我如何在python webdriver中设置chrome的代理

我正在使用此代码:

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy.server.address")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
Run Code Online (Sandbox Code Playgroud)

在python webdriver中设置FF的代理.这适用于FF.如何在Chrome中设置这样的代理?我发现这个例子但不是很有帮助.当我运行脚本时没有任何反应(Chrome浏览器未启动).

python proxy google-chrome webdriver

39
推荐指数
6
解决办法
7万
查看次数

Selenium WebDriver偶尔会抛出超时异常

使用硒对我们的项目进行ui测试.我们正在运行最新版本2.30.0.我们使用Firefox WebDriver并运行Firefox 19.0.

一般来说,当我在Visual Studio中运行ui测试时,ui测试在本地甚至服务器端工作.我们的ui测试在我们的构建服务器上得到了很好的执行.它在我通过Visual Studio手动测试的同一台服务器上使用相同的部署.

但是偶尔我们在构建服务器上执行ui测试时会遇到以下问题:

Test(s) failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:7056/hub/session/bed1d0e7-efdc-46b6-ba07-34903519c44d/element/%7B8717bb19-96c7-44d3-b0ee-d4b989ae652d%7D/click timed out after 60 seconds.
      ----> System.Net.WebException : The operation has timed out
       at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
Run Code Online (Sandbox Code Playgroud)

基本上,测试点击上传按钮,其中输入字段之前填充了文件.由于文件非常小,因此可在几秒钟内完成.然而,有时达到60秒的时间.

任何想法如何隔离潜在的问题?或者之前让任何人遇到同样的问题?任何提示赞赏.谢谢.

.net c# testing selenium webdriver

38
推荐指数
3
解决办法
4万
查看次数