from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
# go to the google home page
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)
这会打开一个Firefox窗口,但不会打开网址.
1或2可以成为问题吗?如果是,那我该如何解决呢?
System.addProperty("webdriver.chrome.driver", ".../chromedriver.exe"); 在实例化驱动程序之前,我遇到了一些似乎已解决问题的问题.
我没有运气,我仍然得到文件.../bin/Debug/chromedriver.exe不存在的错误.
有没有人有幸运行而不把它放在bin文件夹中?
示例代码:
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"c:\path\to\driver\chromedriver.exe");
BrowserDriver = new ChromeDriver();
Run Code Online (Sandbox Code Playgroud) 我是Selenium的新手,我被困在这里:
我想使用Selenium WebDriver 获取下拉列表的选定标签或值,然后在控制台上打印.
我可以从下拉列表中选择任何值,但我无法检索所选值并将其打印出来.
Select select = new
Select(driver.findElement(By.id("MyDropDown"))).selectByVisibleText(data[11].substring(1 , data[11].length()-1));
WebElement option = select.getFirstSelectedOption();
Run Code Online (Sandbox Code Playgroud)
但我所有的努力都是徒劳无益任何帮助都将受到赞赏.提前致谢 :)
很长一段时间我在这里遇到了一些问题.我无法弄清楚,有人愿意帮助我吗?...当我要完成新窗口的任务后,我要切换新窗口.我想关闭那个新窗口.切换旧窗口,
所以这里我写的代码如下:
// Perform the click operation that opens new window
String winHandleBefore = driver.getWindowHandle();
// Switch to new window opened
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
}
// Perform the actions on new window
driver.findElement(By.id("edit-name")).clear();
WebElement userName = driver.findElement(By.id("edit-name"));
userName.clear();
try
{
driver.quit();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("not close");
}
driver.switchTo().window(winHandleBefore);// Again I want to start code this old window
Run Code Online (Sandbox Code Playgroud)
上面我写了代码driver.quit()或driver.close().但我收到了错误.有谁能够帮我...?
org.openqa.selenium.remote.SessionNotFoundException:调用quit()后无法使用FirefoxDriver.
WebElement body = browser.findElement(By.xpath("//body"));
body.findElement(By.xpath("")); // I want to get all child elements
// inside body, but nothing deeper.
Run Code Online (Sandbox Code Playgroud)
示例文档.
<html>
<body>
<div>
</div>
<span>
<table>
</table>
</span>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
预期的结果是div和span.我无法控制文件,而且差异很大.
Selenium似乎有很多不同的组件,网站也没有很好地解释它们,我仍然有点困惑哪个是哪个.两者之间的区别或目的是什么:
Selenium IDE Selenium Server Selenium远程控制WebDriver Selenium 2
我的理解如下:
Selenium IDE是一个GUI插件,用于Selenese/HTML中测试用例的快速原型设计.
Selenium Server是一个独立的java程序,它允许您在各种不同的浏览器中运行HTML测试套件,以及报告等额外选项.
Selenium Remote Control是Selenium Server的旧名称,它仅支持Selenium API的版本1.
WebDriver是实际的核心API,它具有多种语言的绑定,允许您编写独立的测试.
Selenium 2是Selenium项目的最新版本,包括IDE,Server和WebDriver.
我想在linux服务器上使用selenium2的chrome webdriver运行自动化测试.
我已经设置了firefox来使用Xvfb在服务器上运行(参见http://www.semicomplete.com/blog/geekery/xvfb-firefox.html),并希望用chrome做类似的事情.这可能吗?
我正在使用Selenium 2 Web Driver和C#.Net创建测试.在阅读了很多Selenium文档之后,我仍然不确定如何使用PageObject设计模式进行测试.
许多selenium示例仅在Java中显示,并且.Net的API绑定并不总是与人们认为的由于限制和某些语言设置的标准相似.
在.Net Selenium Web Driver中将PageObject设计模式与PageFactory一起使用的最佳方法是什么?
最终,我希望我的PageObjects处理更多功能,而不是使用PageObject IWebElements进行NUnit测试.
下面是我目前如何创建我的测试的示例.
public class LoginPage
{
private IWebDriver webDriver;
[FindsBy(How = How.Id, Using = "ctl00_ctl00_ctl00_insideForm_insideForm_content_txtPassword")]
public IWebElement Password { get; set; }
[FindsBy(How = How.Id, Using = "ctl00_ctl00_ctl00_insideForm_insideForm_content_cmdSubmit")]
public IWebElement SubmitButton { get; set; }
[FindsBy(How = How.Id, Using = "ctl00_ctl00_ctl00_insideForm_insideForm_content_txtUserName")]
public IWebElement UserName { get; set; }
public LoginPage() { }
public LoginPage(IWebDriver webDriver)
{
this.webDriver = webDriver;
if(!webDriver.Url.Contains("Login.aspx"))
{
throw new StaleElementReferenceException("This is not the login page");
} …Run Code Online (Sandbox Code Playgroud) 我在TextBox或Combobox中输入一个值,并希望检索刚刚输入的值.我看到Selenium Weblement方法'getText()'没有检索值,似乎输入的文本没有被推入DOM.
任何方案?
我想找到这个链接"us states"的元素<h5>.我在craigslist中尝试这个.任何帮助将受到高度赞赏
这是网址:http: //auburn.craigslist.org/
<html class="">
<head>
<body class="homepage w1024 list">
<script type="text/javascript">
<article id="pagecontainer">
<section class="body">
<table id="container" cellspacing="0" cellpadding="0"
<tbody>
<tr>
<td id="leftbar">
<td id="center">
<td id="rightbar">
<ul class="menu collapsible">
<li class="expand s">
<li class="s">
<li class="s">
<h5 class="ban hot">us states</h5>
<ul class="acitem" style="display: none;">
</li>
<li class="s">
<li class="s">
Run Code Online (Sandbox Code Playgroud)