我在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文档似乎有很多关于选择元素但没有关于属性的内容.
我已经在我的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) get()
和navigate()
方法有什么区别?是否有任何此方法或其他方法等待加载页面内容?我真正需要的是像selenium WaitForPageToLoad
WaitForPageToLoad webdriver
webdriver` 这样的东西.
有什么建议?
我正在使用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
我一定在想这个错误.
我想在我使用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将它们填充到上一个命令中,我可以在脚本运行时在实际网页上看到它们.
但我需要将内容恢复为数据.
我该怎么做才能读到这个?优选地,以通用方式使得我可以从各种类型的元素中提取内容.
我有一个问题 - 我使用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"Selenium测试(使用Selenium IDE或手动创建),您可以使用一些非常方便的命令,如WaitForElementPresent
或WaitForVisible
.
<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循环似乎也非常笨拙...
我正在使用Selenium Web Driver API和Java.每次我想调试我的测试用例时,都会在临时文件目录中创建Firefox的临时配置文件.这在两个方面令人头疼.
我该如何解决这个问题?
我正在使用Protractor执行一些端到端测试,我想通过命令行传入登录凭据,而不是将它们存储在spec文件中.我发现有人使用了一个帖子process.argv.forEach
,但是如何存储这些值并在另一个spec文件中使用它们?我有一个文件login-spec.js
,我想使用命令行参数.
谢谢!
截至本文发布之日,"Microsoft Edge"这个名称刚刚被正式宣布为新Windows 10的默认浏览器.
现在提问可能为时过早,但我想知道是否可以使用新的Selenium WebDriver,如果没有,是否有任何说明我们可以期待等待多长时间才能看到一个已开发的?
(Windows 10的技术预览已经出来,所以这对我来说似乎不是一个愚蠢的问题.)
selenium webdriver selenium-webdriver microsoft-edge selenium-edgedriver
webdriver ×10
selenium ×8
java ×4
python ×4
angularjs ×1
firefox ×1
getattribute ×1
html ×1
javascript ×1
profile ×1
protractor ×1
selenium-ide ×1
time-wait ×1