见下面的测试夹具:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
/// <summary>
/// Tests relating to Harry Potter
/// </summary>
[TestFixture("Dumbledore")]
public class HarryPotterTests
{
public string Name;
public HarryPotterTests(string personName)
{
Name = personName;
}
[Test]
public void Test()
{
Console.WriteLine(Name);
}
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是查看参数化测试装置的工作原理.我之前没有使用它们,所以这是我第一次尝试它.
它对我来说很好看.带有字符串的构造函数,并在实际测试fixture属性中传入一个字符串.它汇编.测试只是将其写入控制台窗口.
然而,测试失败并显示以下消息:
No suitable constructor was found
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西吗?
无论我在哪里设置断点,都没有任何打击,所以它很早就失败了.
我想检查用户是否可以在不滚动的情况下在当前Web浏览器视图中看到元素.
我发现的可以检查元素是否在页面上的某个位置.
另一个暗示建议检查元素位置但是我需要获得浏览器的可见窗口的尺寸加上其x/y偏移量为0/0.
如果有人能指出我不需要JavaScript代码的解决方案,我将不胜感激.
我正在开发一个具有基于Web的前端的系统,我正在使用Selenium进行测试.在一个页面上,当向下滚动时内容是动态加载的(也许你知道来自Facebook的朋友列表),因为这是其中一个要求.
使用Selenium Webdriver(我使用Chrome)向下滚动应该没有问题通过Javascript.但是动态添加的内容存在问题.如何让Webdriver找到这些元素?
我尝试了以下内容向下滚动,直到不再加载内容:
int oldSize = 0;
int newSize = 0;
do {
driver.executeScript("window.scrollTo(0,document.body.scrollHeight)");
newSize = driver.findElementsBy(By.cssSelector("selector").size();
} while(newSize > oldSize);
Run Code Online (Sandbox Code Playgroud)
但是,虽然页面第一次向下滚动,而现在一些内容正确加载,但驱动程序的findElementsBy(By)函数找不到它们.
有人曾遇到过这个问题吗?如果有人能帮助我找到解决办法,我会很高兴的!
此致,本杰明
我想在VS 2010 C#中使用Selenium Web Driver打开Chrome浏览器,导航到某个网页,然后关闭驱动程序,但保持浏览器打开.我意识到之后我将不得不手动关闭浏览器,我很好.
到目前为止,我有:
DriverService service = ChromeDriverService.CreateDefaultService();
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("chrome.detach",true);
m_driver = new ChromeDriver(service, options, TimeSpan.FromMilliseconds(1000));
[m_driver does stuff like navigate page, double click stuff, etc]
[last line: try to close driver but not browser]
Run Code Online (Sandbox Code Playgroud)
我已经尝试了以下所有内容作为最后一行
m_driver.Dispose(); // closes both browser and driver
m_driver.Close(); //closes just the browser and not the driver
m_driver.Quit(); // closes both browser and driver
service.Dispose(); // closes both browser and driver
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个按钮:
<input type="button" onclick="onOpenSessionClick()" value="Open device access">
Run Code Online (Sandbox Code Playgroud)
但是当我执行命令时:
driver.findElement(By.xpath("//input[@value='Open access device' and @type='submit']")).click();
Run Code Online (Sandbox Code Playgroud)
点击不会.这是我的代码:
if (isElementPresent((By.xpath("//input[@value='Open device access']"))))
{
System.out.println("Je suis dans le if");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@value='Open device access' and @type='submit']")).click();
System.out.println("Je suis dans le if et jai open");
Thread.sleep(5000);
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div/p/span")));
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input")));
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input[2]")));
System.out.println("Je suis dans le if et je cherche");
}
Run Code Online (Sandbox Code Playgroud) 在Selenium Nodejs中,如何获取我正在测试的页面的当前URL(我的测试脚本运行的那一刻假设页面最初被重定向)
我试图突出(使用C#在selenium webdriver中找到的元素).我搜索网上所有我发现的是java代码,但需要它在C#中.
或者还有其他方法可以做到这一点.
谢谢
我正在尝试编写代码来选择 HTML 下拉菜单的所有选项。我已经编写了以下我认为应该可以工作的代码。
public void testSelectMultipleOptions () {
// code to get to report page
selectAllOptions("param.Status");
// code to run report and switch to the result page
}
public void selectAllOptions(String htmlID) {
List<WebElement> options = selenium.findElements(By.cssSelector("select#"+htmlID+" > option"));
for(WebElement option: options) {
option.click();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,下拉列表中没有选择任何选项。我相信我遇到的问题是由于我有一个 HTML 元素在 id 中带有句点,但我无法更改页面的底层 HTML 代码。
我一直在尝试将注册表文件导出并保存到任意位置,代码正在运行.但是,在指定路径和保存时,该功能不起作用,也不会导出注册表.也没有显示错误.
private static void Export(string exportPath, string registryPath)
{
string path = "\""+ exportPath + "\"";
string key = "\""+ registryPath + "\"";
// string arguments = "/e" + path + " " + key + "";
Process proc = new Process();
try
{
proc.StartInfo.FileName = "regedit.exe";
proc.StartInfo.UseShellExecute = false;
//proc.StartInfo.Arguments = string.Format("/e", path, key);
proc = Process.Start("regedit.exe", "/e" + path + " "+ key + "");
proc.WaitForExit();
}
catch (Exception)
{
proc.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud) 我无法使用selenium查找登录ID.我之前在Windows计算机上完成了这项工作,但是我想在家里在我的Mac上做这个,我不能再找到id的元素了.我已经尝试实现了很多人在线建议的driverwait,但我仍然遇到同样的错误.任何帮助将不胜感激.
public class mainEntry {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String webPage;
//theDriver driverCMD = new theDriver();
WebDriver driverCMD = new FirefoxDriver();
login start = new login("https://jira.arbonne.com/", driverCMD);
start.loginWithUser();
}
}
Run Code Online (Sandbox Code Playgroud)
登录页面对象如下:
public class login {
String webpage;
WebDriver driverCMD;
login(String webpage, WebDriver driverCMD)
{
this.webpage = webpage;
this.driverCMD = driverCMD;
}
public void loginWithUser()
{
WebDriverWait wait = new WebDriverWait(driverCMD, 300); // The int here is the maximum …Run Code Online (Sandbox Code Playgroud) 我在选择框架中的项目时遇到问题.我到了某一点然后失败了.我尝试了很多选项,但无济于事,下面是代码.我进入第一帧然后:
selenium.open("http://localhost/Clockwise/Main.htm");
// grabs back to driver
WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
driver.switchTo().frame("MainFrame");
//selenium.selectFrame("MainFrame");
driver.findElement(By.xpath("//li[contains(.,'Reports')]")).click();
//selenium.click("//li[contains(.,'Reports')]")
driver.findElement(By.xpath("//li[contains(.,'Reports')]")).click();
driver.findElement(By.xpath("//li[contains(.,'Reports')]"));
Thread.sleep(3000);
//FAILS HERE
driver.findElement(By.id("SELECTALL2")).click();
Run Code Online (Sandbox Code Playgroud) 我想上传5个文件,但我的'文件输入'是同名/ id,我怎么能上传5个文件.我的HTML代码是:
<div>
<table id="listtable">
</table>
<br/>
<input type="hidden" name="delFiles" id="deletefiles"/>
<table id="filetable">
<tbody>
<tr>
<td>
<input type="file" size="27px" id="page" name="page"/>
</td>
<td>
<a href="#">
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</a>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> …Run Code Online (Sandbox Code Playgroud) 我正在玩我正在编写的C#应用程序中遇到的一些错误.我一直得到的错误是:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string pw ="", hash =""; //Declare an intialise variables
if (args.Length < 4) // Test to see if correct number of arguments have been passed
{
Console.WriteLine("Please use command line arguments in this format: encrypt -e (or -d) password-to-encrypt-with input-file output-file");
Environment.Exit(0);
}
if (args[1].Length < 10 || args[1].Length > 40) // Test to see if the password is between 10 …Run Code Online (Sandbox Code Playgroud) selenium ×10
webdriver ×6
c# ×5
java ×2
command-line ×1
export ×1
gui-testing ×1
node.js ×1
nunit ×1
registry ×1
unit-testing ×1