很长一段时间我在这里遇到了一些问题.我无法弄清楚,有人愿意帮助我吗?...当我要完成新窗口的任务后,我要切换新窗口.我想关闭那个新窗口.切换旧窗口,
所以这里我写的代码如下:
// 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.
在Selenium Grid中我试图执行一个简单的程序,Cannot find firefox binary in PATH虽然我已经在我的代码中添加了二进制路径.
我的代码和错误如下.请帮忙.提前致谢.
码
package Sample;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class sample1 {
WebDriver driver;
String BaseURL,NodeURL;
@BeforeTest
public void beforeTest() throws MalformedURLException {
BaseURL="www.google.com";
NodeURL="http://192.168.10.162:5566/wd/hub";
DesiredCapabilities capa =DesiredCapabilities.firefox();
capa.setBrowserName("firefox");
capa.setCapability("binary", "C:\\Users\\praveenraj.d\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
capa.setPlatform(Platform.ANY);
driver=new RemoteWebDriver(new URL(NodeURL),capa);
}
@Test
public void f() throws InterruptedException {
driver.get(BaseURL);
System.out.println(driver.getTitle());
Thread.sleep(50000);
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Run Code Online (Sandbox Code Playgroud)
错误 …
我创建了一个 Cucumber 功能文件和步骤文件,然后单击功能文件的“运行配置”,我在控制台中看到以下内容。我怎么解决这个问题?
\n*Feature: Login into account\n Existing user should be able to login to account using correct credentials\n \nScenario: Login into account with correct credentials # C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4\n \nGiven User navigates to stackoverflow website # LoginSteps.user_navigates_to_stackoverflow_website()\n java.lang.ExceptionInInitializerError\n at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)\n at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)\n at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)\n at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)\n at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)\n at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)\n at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)\n at cucumber.runtime.Runtime.runStep(Runtime.java:300)\n at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)\n at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)\n at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)\n at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)\n at cucumber.runtime.Runtime.run(Runtime.java:122)\n at cucumber.api.cli.Main.run(Main.java:36)\n at cucumber.api.cli.Main.main(Main.java:18)\n at \xe2\x9c\xbd.Given User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:5)\n \n Caused by: java.lang.reflect.InaccessibleObjectException: Unable …Run Code Online (Sandbox Code Playgroud) 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) 我正在尝试使用python和selenium来自动执行firefox中的一些任务.当我下载文件时,弹出窗口询问您是否要打开或保存,以及每次使用此类文件执行此操作的复选框.我发现除非您在网页修复工具上安装添加,否则复选框不起作用.我有正常安装,但当我使用python + selenium时,它使用没有添加的配置文件.
互联网已指示我通过关闭Firefox,打开/ Applications/Utilities,然后键入命令来创建另一个配置文件:
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
Run Code Online (Sandbox Code Playgroud)
然后我创建一个新的配置文件,我将使用selenium.我设置名称并更改文件夹名称.配置文件名称为"PTI_Auto_Profile".文件夹路径显示如下:
/users/User/Library/Application Support/Firefox/Profiles/Selenium/
Run Code Online (Sandbox Code Playgroud)
当我完成.我点击"启动Firefox",终端屏幕上出现以下错误.
2013-04-11 11:57:30.422 firefox-bin[2248:707] invalid drawable
conf-room:~ User$ 2013-04-11 11:58:00.350 firefox-bin[2251:303] invalid drawable
Run Code Online (Sandbox Code Playgroud)
我试过以下没有成功.
profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(firefox_profile=profile)
Run Code Online (Sandbox Code Playgroud)
没有错误,默认用户.
profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(profile)
Run Code Online (Sandbox Code Playgroud)
没有错误,默认用户.
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv/xls")
driver = webdriver.Firefox(firefox_profile=fp)
Run Code Online (Sandbox Code Playgroud)
错误:fp.set_preference("browser.download.dir",getcwd())NameError:名称'getcwd'未定义
关于我做错了什么的任何想法?谢谢!
ps我使用的是mac os x 10.8.2,python 2.7,firefox 20
Corey Goldberg提供的解决方案.这适用于所有excel版本.
import os
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/vnd.ms-excel'))
driver = …Run Code Online (Sandbox Code Playgroud) 我想找到这个链接"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) 我正在尝试通过Selenium做一些webscraping.我的问题很简单:你如何找到一个链接然后如何点击它?例如:以下是我尝试网络抓取的HTML:
<td bgcolor="#E7EFF9">
<a href="javascript:selectDodasaDetdasdasy(220011643,'Kdasdas?');" target="_self">
Details
</a>
</td>
Run Code Online (Sandbox Code Playgroud)
所以,你可以看到"细节"这个词是一个链接.
如何使用Selenium找到该链接并单击它?
python web-scraping python-2.7 python-3.x selenium-webdriver
我在使用 Google 登录时遇到问题。我想登录我的帐户,但 Google 说不允许自动化驱动程序登录。
我正在寻找解决方案。是否可以获取普通 Firefox/Chrome 的 cookie 并将其加载到 ChromeDriver/GeckoDriver 中?我认为这可以是一个解决方案。但我不确定这是否可能..
正在寻找解决方案...
另外,我想添加一个快速解决方案。我通过使用我的旧验证帐户之一解决了这个问题。这对你来说是一个快速的解决方案。
selenium google-chrome selenium-chromedriver selenium-webdriver geckodriver
selenium ×5
webdriver ×5
java ×3
python ×2
bdd ×1
c# ×1
cucumber ×1
firefox ×1
geckodriver ×1
macos ×1
pageobjects ×1
python-2.7 ×1
python-3.x ×1
web-scraping ×1
xvfb ×1