小编Yi *_*eng的帖子

如何生成随机数

我必须使用Selenium IDE创建一个家庭作业测试,并创建一个场景来生成一个随机数.我正在努力解决我需要输入的内容以及输入的字段.

我应该输入什么?:命令目标值

selenium selenium-ide

4
推荐指数
1
解决办法
2万
查看次数

WebDriver Actions.Perform()或Actions.Build().Perform()

我在C#中使用Selenium2 WebDriver

Actions.Build - 返回IAction可用于执行操作的组合.(IActions有一个执行操作的Perform方法)Actions.Perform - 执行当前构建的操作.

在大多数考试中使用这样的动作:

new Actions(IWebDriverObj).actions...Build().Perform()
Run Code Online (Sandbox Code Playgroud)

但这也有效

new Actions(IWebDriverObj).actions...Perform()  //no Build before Perform
Run Code Online (Sandbox Code Playgroud)

是否有必要在Perform()或Build()之前使用Build()仅用于某些兼容性目的?

提前谢谢你的答案

c# selenium webdriver selenium-webdriver

4
推荐指数
1
解决办法
7409
查看次数

设置具有选项和功能的selenium Webdriver

虽然我需要通过正确的设置启动驱动程序,但使用硒很容易

所以现在我只需要忽略缩放级别

我的代码是:

public string path = AppDomain.CurrentDomain.BaseDirectory;
public IWebDriver WebDriver;
var ieD = Path.Combine(path, "bin");

DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
caps.SetCapability("ignoreZoomSetting", true);
Run Code Online (Sandbox Code Playgroud)

现在我的当前代码只传递驱动程序的路径作为参数

WebDriver = new InternetExplorerDriver(ieD);
Run Code Online (Sandbox Code Playgroud)

我怎样才能正确传递能力和驱动程序路径?

c# asp.net selenium automation selenium-webdriver

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

如何使用ExtJS在页面上找到元素的唯一选择器以与Selenium一起使用?

我正在使用Selenium和Firefox Webdriver来处理页面上具有唯一CSS ID的元素(在每个页面加载时),但ID每次都会更改,因此我无法使用它们来定位元素.这是因为该页面是使用ExtJS构建的Web应用程序.

我正在尝试使用Firebug来获取元素信息.

我需要找到一个独特的xPath或选择器,以便我可以使用Selenium单独选择每个元素.

当我使用Firebug复制xPath时,我得到一个这样的值:

//*[@id="ext-gen1302"]
Run Code Online (Sandbox Code Playgroud)

但是,下次加载页面时,它看起来像这样:

//*[@id="ext-gen1595"]
Run Code Online (Sandbox Code Playgroud)

在该页面上,每个元素都具有此ID格式,因此CSS ID不能用于查找元素.

我希望得到xPath在DOM中的位置,但Firebug只会返回ID xPath,因为它对于该页面实例是唯一的.

/html/body/div[4]/div[3]/div[4]/div/div/div/span[2]/span
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得Firebug(或其他能以相似速度工作的工具)给我一个独特的选择器,即使在ext-gen ID发生变化之后也可以用它来查找Selenium的元素?

selenium xpath extjs webdriver selenium-webdriver

4
推荐指数
1
解决办法
2万
查看次数

java sendkeys错误键应该是一个字符串

我尝试使用用户名和密码传递给表单字段时收到错误sendKeys.下面是我的用户类,后面是我的测试类.有谁知道为什么应用程序没有传递字符串?

org.openqa.selenium.WebDriverException:未知错误:keys应该是一个字符串

public class User {
    public static String username;
    public static String password;


    public User() {
        this.username = "username";
        this.password = "password";
    }

    public String getUsername(){
        return username;
    }

    public String getPassword(){
        return password;
    }

}

@Test
public void starWebDriver()  {
    driver.get(domainURL.getURL());
    WebElement userInputBox, passInputBox;
    userInputBox = driver.findElement(By.xpath("//input[@name='email']"));
    passInputBox = driver.findElement(By.xpath("//input[@name='password']"));
    System.out.println("before sending keys");
    userInputBox.sendKeys(User.username);
}
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver selenium-webdriver

4
推荐指数
1
解决办法
2万
查看次数

在Selenium中使用javascript停用Google Analytics

我正在使用硒来测试生产现场.测试活动与分析一起拧紧.

我可以通过Selenium在页面加载后使用JavaScript禁用分析吗?我知道我可以通过Selenium执行JS.问题是,如何禁用GA代码?

selenium google-analytics selenium-webdriver

4
推荐指数
1
解决办法
2420
查看次数

Ruby selenium 无法加载此类文件 -- selenium-webdriver (LoadError)

我正在尝试使用 ruby​​ 和 Selenium WebDriver 和 Eclipse 来利用 BrowserStack 的自动化测试。

这是我试图运行的代码:

require 'rubygems'
require 'selenium-webdriver'

# Input capabilities
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browser"] = "IE"
caps["browser_version"] = "7.0"
caps["os"] = "Windows"
caps["os_version"] = "XP"
caps["browserstack.debug"] = "true"
caps[:name] = "Testing Selenium 2 with Ruby on BrowserStack"

driver = Selenium::WebDriver.for(:remote,
  :url => "http://xxxxxxxxxxxxx:xxxxxxxxxxxxxx@hub.browserstack.com/wd/hub",
  :desired_capabilities => caps)
driver.navigate.to "http://www.google.com/ncr"
element = driver.find_element(:name, 'q')
element.send_keys "BrowserStack"
element.submit
puts driver.title

driver.quit
Run Code Online (Sandbox Code Playgroud)

这是我遇到的错误:

/Users/user/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- selenium-webdriver (LoadError)
from /Users/user/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require'
from …
Run Code Online (Sandbox Code Playgroud)

ruby eclipse selenium browserstack

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

设置PhantomJS C#中的屏幕尺寸由Selenium驱动

如何设置浏览器屏幕大小?当我将PhantomJS设置为低于其仅显示400px宽图像时拍摄屏幕截图.

var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LoadImages = false;
driverService.ProxyType = "none";      

using (var driver = new PhantomJSDriver(driverService))
{
    etc....
}
Run Code Online (Sandbox Code Playgroud)

c# selenium webdriver phantomjs selenium-webdriver

4
推荐指数
1
解决办法
6572
查看次数

使用Selenium Python绑定读取div中的隐藏值

问题:如何读取嵌套中的值<div>

情况:我正在我们的网站上测试注册.为了完成该过程,用户将需要输入验证码.使用帮助程序类(在我们的开发服务器上),我们可以显示(隐藏)当前的验证码.我需要抓住它并保存它以供.send_keys函数使用(该部分是简单的部分).我没有代码与我正在使用的东西分享,因为我甚至不确定在哪里跳.

好吧,我有这个,但这显然不是答案:

driver.find_element_by_id("capchta").send_keys("foobar")
Run Code Online (Sandbox Code Playgroud)

在上面,我可以发送一个键值(看作"foobar").我只需要用我在中读到的字符串替换"foobar"value=XXX

这是带有验证码的HTML代码,用value=XXXX.表示.

<div id="code_area">
     <p id="captcha_blurb">Please enter the security code below</p>
     <div id="capchta_area">
     <img id="secuity_icon" src="/img3/Secuity-Icon.png">
     <img id="security-image" src="data:image/png;==">
     <input id="current_captcha" type="hidden" value="XXXX">
     <input id="capchta" class="reg_form_input" value="" name="code" placeholder="Enter Security Code" title=" Please Enter These Characters." onblur="removeInputInfoBox('reg_box');" onfocus="addInputInfoBox('#capchta','#capchta_area', 'reg_box');">
</div>
Run Code Online (Sandbox Code Playgroud)

python selenium webdriver selenium-webdriver

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

RSpec 在期望 raise_error 之前期望一些东西

想象一下有一种方法可以救援并进行一些日志记录。

def do_something
  # do stuff
  some_client.call(var1)
rescue StandardError => e
  # log some stuff.
  Rails.logger.error("#{self.class} - Var 1 is #{var1}.") if e.is_a?(MyError)

  raise
end
Run Code Online (Sandbox Code Playgroud)

然后在 RSpec 中,我想

  • 断言引发错误。
  • 它记录错误
before do
  allow(Rails.logger).to receive(:error)
  allow(some_client).to receive(:call).and_raise(MyError)
end

it "logs the error" do
  subject

  expect(Rails.logger).to have_received(:error).with(/some message with var1/)
end

it "raises MyError" do
  expect { subject }.to raise_error(MyError)
end
Run Code Online (Sandbox Code Playgroud)

expect { subject }.to raise_error(MyError)部分按预期工作,但我应该如何断言日志记录?使用上面的示例代码,RSpec 将报告引发的错误,而不断言日志记录。

rspec ruby-on-rails

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