标签: webdriver

如何从Selenium获取元素的属性?

我在Python中使用Selenium.我想得到.val()一个<select>元素,并检查它是我期望的.

这是我的代码:

def test_chart_renders_from_url(self):
    url = 'http://localhost:8000/analyse/'
    self.browser.get(url)
    org = driver.find_element_by_id('org')
    # Find the value of org?
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?Selenium文档似乎有很多关于选择元素但没有关于属性的内容.

python selenium webdriver getattribute selenium-webdriver

61
推荐指数
3
解决办法
10万
查看次数

如何修复Selenium WebDriverException:在我们连接之前,浏览器似乎已经退出了?

我已经在我的centos6.4服务器上安装了firefox和Xvfb来使用selenium webdriver.

但是,当我运行代码时,我收到了一个错误.

from selenium import webdriver
browser = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)

错误

selenium.common.exceptions.WebDriverException: Message: 
'The browser appears to have exited before we could connect. The output was: None'
Run Code Online (Sandbox Code Playgroud)

我在stackoverflow上读了一些相关的页面,有人建议删除tmp文件夹中的所有文件,所以我做到了.但是,它仍然无效.

有人可以帮我一个忙吗?

先感谢您!

编辑

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 64, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
    self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited     before …
Run Code Online (Sandbox Code Playgroud)

python selenium webdriver selenium-webdriver

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

webdriver.get()和webdriver.navigate()之间的区别

get()navigate()方法有什么区别?是否有任何此方法或其他方法等待加载页面内容?我真正需要的是像selenium WaitForPageToLoadWaitForPageToLoad webdriverwebdriver` 这样的东西.

有什么建议?

java webdriver time-wait selenium-webdriver

59
推荐指数
3
解决办法
16万
查看次数

必须通过webdriver.ie.driver系统属性设置驱动程序可执行文件

我正在使用Selenium来自动化测试.我的应用程序专门使用IE,它不适用于其他浏览器.

码:

import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Test {
    public static void main(String[] args) {
        final String sUrl = "http://www.google.co.in/";                             
        System.setProperty("webdriver.chrome.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe");
        WebDriver oWebDriver = new InternetExplorerDriver();
        oWebDriver.get(sUrl);
        WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); // Use name locator to identify the search input field.
        oSearchInputElem.sendKeys("Selenium 2");
        WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[@name='btnG']"));  
        oGoogleSearchBtn.click();

        try {
            Thread.sleep(5000);
        } catch(InterruptedException ex) {
            System.out.println(ex.getMessage());
        }
        oWebDriver.close();
    }    
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误

必须通过webdriver.ie.driver系统属性设置驱动程序可执行文件的路径; 有关更多信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver.最新版本可以从http://www.seleniumhq.org/download/ 2012年6月12日下午4:18:42 下载org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO:I/O异常(java.处理请求时捕获的net.SocketException:软件导致连接中止:recv失败2012年6月12日下午4:18:42 org.apache.http.impl.client.DefaultRequestDirector tryExecute

有人可以帮我吗?

java internet-explorer webdriver system-properties selenium-webdriver

57
推荐指数
2
解决办法
22万
查看次数

如何在webdriver中获取元素的当前内容

我一定在想这个错误.

我想在我使用Webdriver/Selenium 2访问的页面上获取元素的内容,在本例中为formfield

这是我破碎的代码:

 Element=driver.find_element_by_id(ElementID)
 print Element
 print Element.text
Run Code Online (Sandbox Code Playgroud)

这是结果:

<selenium.webdriver.remote.webelement.WebElement object at 0x9c2392c>
Run Code Online (Sandbox Code Playgroud)

(注意空白行)我知道该元素有内容,因为我只是使用.sendkeys将它们填充到上一个命令中,我可以在脚本运行时在实际网页上看到它们.

但我需要将内容恢复为数据.

我该怎么做才能读到这个?优选地,以通用方式使得我可以从各种类型的元素中提取内容.

python selenium webdriver

56
推荐指数
2
解决办法
10万
查看次数

Python - Selenium WebDriver - 检查元素存在

我有一个问题 - 我使用selenium(firefox)网络驱动程序打开网页,点击几个链接等然后捕获截图.

我的脚本在CLI中运行良好,但是当通过cronjob运行时,它没有超过第一个find_element()测试.我需要添加一些调试,或者某些东西来帮助我找出它失败的原因.

基本上,我必须在进入登录页面之前单击"登录"锚点.元素的构造是:

<a class="lnk" rel="nofollow" href="/login.jsp?destination=/secure/Dash.jspa">log in</a>
Run Code Online (Sandbox Code Playgroud)

我正在使用find_element By LINK_TEXT方法:

login = driver.find_element(By.LINK_TEXT, "log in").click()
Run Code Online (Sandbox Code Playgroud)

我有点像Python Noob,所以我正在与语言作斗争......

A)如何检查链接是否实际被python拾取?我应该使用try/catch块吗?

B)是否有比LINK_TEXT更好/更可靠的方法来定位DOM元素?例如,在JQuery中,您可以使用更具体的选择器$('a.lnk:contains(登录)').do_something();


我已经解决了主要问题,这只是手指麻烦 - 我用不正确的参数调用脚本 - 简单的错误.

我仍然喜欢一些关于如何检查元素是否存在的指针.另外,隐式/显式Waits的示例/解释而不是使用糟糕的time.sleep()调用.

干杯,ns

html python selenium webdriver

55
推荐指数
6
解决办法
12万
查看次数

使用Java的Selenium WebDriver测试中等效的waitForVisible/waitForElementPresent?

使用"HTML"Selenium测试(使用Selenium IDE或手动创建),您可以使用一些非常方便的命令,WaitForElementPresentWaitForVisible.

<tr>
    <td>waitForElementPresent</td>
    <td>id=saveButton</td>
    <td></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

在用Java编写Selenium测试时(Webdriver/Selenium RC-我不确定这里的术语),是否有类似内置的东西

例如,用于检查对话框(需要一段时间才能打开)是可见的...

WebElement dialog = driver.findElement(By.id("reportDialog"));
assertTrue(dialog.isDisplayed());  // often fails as it isn't visible *yet*
Run Code Online (Sandbox Code Playgroud)

编码此类检查的最简洁的方法是什么?

Thread.sleep()在整个地方添加调用将是丑陋和脆弱的,并且滚动自己的while循环似乎也非常笨拙...

java selenium webdriver selenium-ide selenium-webdriver

54
推荐指数
2
解决办法
15万
查看次数

如何阻止Selenium使用Web Driver创建临时Firefox配置文件?

我正在使用Selenium Web Driver API和Java.每次我想调试我的测试用例时,都会在临时文件目录中创建Firefox的临时配置文件.这在两个方面令人头疼.

  1. 它肯定会花费不必要的时间来创建一个配置文件,并占用不必要的空间.
  2. 我无法安装下次启动测试用例时可用的任何插件.

我该如何解决这个问题?

java profile firefox selenium webdriver

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

如何在Angularjs Protractor中使用命令行参数?

我正在使用Protractor执行一些端到端测试,我想通过命令行传入登录凭据,而不是将它们存储在spec文件中.我发现有人使用了一个帖子process.argv.forEach,但是如何存储这些值并在另一个spec文件中使用它们?我有一个文件login-spec.js,我想使用命令行参数.

谢谢!

javascript selenium webdriver angularjs protractor

52
推荐指数
1
解决办法
3万
查看次数

是否有适用于Microsoft Edge浏览器的Selenium WebDriver?

截至本文发布之日,"Microsoft Edge"这个名称刚刚被正式宣布为新Windows 10的默认浏览器.

现在提问可能为时过早,但我想知道是否可以使用新的Selenium WebDriver,如果没有,是否有任何说明我们可以期待等待多长时间才能看到一个已开发的?

(Windows 10的技术预览已经出来,所以这对我来说似乎不是一个愚蠢的问题.)

selenium webdriver selenium-webdriver microsoft-edge selenium-edgedriver

50
推荐指数
3
解决办法
6万
查看次数