Tag: selenium webdriver

Selenium Webdrivers:无任何资源加载页面

我试图阻止Javascript更改我正在使用Selenium测试的网站源代码。 问题是,我不能简单地在Webdriver中关闭Javascript,因为我需要它来进行测试。 这是我正在为Firefox Webdriver做的事情: firefoxProfile.setPreference(“permissions.default.image”, 2); firefoxProfile.setPreference(“permissions.default.script”, 2); firefoxProfile.setPreference(“permissions.default.stylesheet”, 2); firefoxProfile.setPreference(“permissions.default.subdocument”, 2); 我不允许Firefox加载任何图像,脚本和样式表。 如何使用Internet Explorer Webdriver和Chrome Webdriver执行此操作? 我没有找到任何类似的偏好。 或者是否有一种更优雅的方式来阻止webdrivers加载网站的JS文件呢? 谢谢!

软断言的工作原理

我知道继续测试,即使一个或多个断言在TestNG中失败。 我在下面提到了链接,以便在我的项目中实现软断言。 http://beust.com/weblog/2012/07/29/reinventing-assertions/ http://seleniumexamples.com/blog/guide/using-soft-assertions-in-testng/ http://www.seleniumtests.com/2008/09/soft-assertion-is-check-which-doesnt.html 但我不理解代码执行的流程,如函数调用,FLOW。 请帮助我理解柔软的工作流程。 码: import org.testng.asserts.Assertion; import org.testng.asserts.IAssert; //Implementation Of Soft Assertion public class SoftAssertions extends Assertion{ @Override public void executeAssert(IAssert a){ try{ a.doAssert(); } catch(AssertionError ex){ System.out.println(a.getMessage()); } } } //Calling Soft Assertion SoftAssertions sa = new SoftAssertions(); sa.assertTrue(actualTitle.equals(expectedTitle), “Login Success, But Uname and Pwd are wrong”); 注意:即使上面的断言失败,执行也会继续 谢谢Mahesh

为页面中的帧实现PageObjects模式

如何为页面中的帧实现pageObject模式(Selenium)..我有一个主页,有一个左框架和右框架,我想为每个框架创建页面对象.. 例如,我有如下的LeftFrame页面对象: Public Class HomePageLeftFrame{ private WebElement link; private WebElement textField; } 如何为HomePageLeftFrame对象中的两个元素编写@FindBy注释…有没有办法? 注意:根据关于pageObjects的selenium的文档,提到页面对象可以是整个HTML页面或页面的一部分。我的理解是否正确上述实现?

如何在Selenium WebDriver中使用@FindBy注释

我想知道我的代码有什么问题,因为当我尝试测试我的代码时,我什么也得不到。 public class SeleniumTest { private WebDriver driver; private String nome; private String idade; @FindBy(id = “j_idt5:nome”) private WebElement inputNome; @FindBy(id = “j_idt5:idade”) private WebElement inputIdade; @BeforeClass public void criarDriver() throws InterruptedException { driver = new FirefoxDriver(); driver.get(“http://localhost:8080/SeleniumWeb/index.xhtml”); PageFactory.initElements(driver, this); } @Test(priority = 0) public void digitarTexto() { inputNome.sendKeys(“Diego”); inputIdade.sendKeys(“29”); } @Test(priority = 1) public […]

如何使用selenium web driver for java获取特定optgroup下的选项?

例如,我想从多选选项列表字段中选择特定optgroup下的选项 pick1 pick2 pick3 pick4 如果选项列表字段如上所述,我可以使用 new Select(driver.findElement(By.id(“xyz”))).selectByVisibleText(“pick1”); new Select(driver.findElement(By.id(“xyz”))).selectByVisibleText(“pick2”); 从上面选择optgroup -Group1下的所有选项。 在这里,我知道Group1中存在哪些选项,因此我可以选择如上所述。 但我的要求是动态的,我需要选择optgroup-Group1下的所有选项。 如果我想动态选择包括组1和组2的所有选项 然后我可以使用 new Select(driver.findElement(By.id(“xyz”))).getOptions(); 将所有选项作为List获取,我可以将其存储为数组,然后我可以使用数组逐个选择所有选项 但是,如何才能在一个特定的optgroup下获得所有选项,比如Group1或Group2?

Selenium偶尔会出现UnreachableBrowserException

我试图通过在Java中使用Selenium来访问多个网站。 偶尔,我得到一个UnreachableBrowserException 。 我已经读过很多关于这个错误的线索,但似乎有很多不同的错误原因。 当我尝试访问新页面时,我得到的错误大约是1%的时间,我发现事件之间没有任何相似之处。 我目前正在使用Firefox,但我也尝试过Internet Explorer并遇到过类似的错误。 我一次只打开一个页面并尝试使用相同的窗口并在尝试访问另一个页面之前完全退出驱动程序,无论哪种方式仍然出现错误。 重要的是要注意我并不总是得到这个错误有时我的代码可以运行而不会发生这种情况。 这是错误消息: Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught when processing request to {}- http://127.0.0.1:7055: Permission denied: connect Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {}->http://127.0.0.1:7055 Jan 12, 2015 10:39:40 PM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught […]

在selenium webderiver中从IDE / Console获取用户输入

我想从用户输入中获取密钥(发送密钥)我应该如何实现它? driver.findElement(By.xpath(“.//*[@id=’vehicleNum’]”)).sendKeys(“1121”);

使用selenium给出错误在java中获取隐藏元素

当我选择值隐藏其显示错误为: 线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法定位元素:{“method”:“部分链接文本”,“选择器”:“vehicle-make”} 这是我的代码: package section5.advWays.locatingObjects; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class CusXPathUsingAtt1 { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub WebDriver wd = new FirefoxDriver(); wd.manage().window().maximize(); Thread.sleep(5000); wd.get(“http://www.tirerack.com/content/tirerack/desktop/en/homepage.html”); Select SelectMakedropdown = new Select(wd.findElement(By.id(“vehicle-make”))); SelectMakedropdown.selectByVisibleText(“BMW”); Select YearSelectDropdown = new Select(wd.findElement(By.id(“vehicle-year”))); YearSelectDropdown.selectByVisibleText(“2011”); Select VehicleSelectDropdown = new Select(wd.findElement(By.id(“vehicle-model”))); […]

Selenium WebDriver在切换之前获取当前帧

通过切换某个iFrame,我有一个自定义操作来查找元素。 它使用以下本机操作: driver.switchTo().frame(requested_frame)目前我在切换到确切的iframe之前每次切换回默认内容。 现在我需要通过以下scnario来提高它的性能: 检查当前内容/框架 如果requested_frame=currentFrame则无需切换 if requested_frame=null然后切换到默认值(如果currentFrame=default则再次无需切换) if requested_frame!=null && requested_frame!=currentFrame然后切换到默认值,并切换到requested_frame帧。 所以我现在需要的是获得当前帧。 有什么方法可以得到它吗?

如何在集线器中注册节点后启动远程webdriver?

我正在尝试启动remoteWebdriver,因为我已经逐步创建了一个集线器,然后我在其上添加了一个节点。 这很好。我执行时的问题: Thread.currentThread().join(); 程序停止执行,如果我删除此行,我会收到错误。 try{ String strIP = “localhost”; GridHubConfiguration config = new GridHubConfiguration(); config.setTimeout(30000000); config.setPort(4444); config.setHost(strIP); Hub hub = new Hub(config); hub.start(); RegistrationRequest req = new RegistrationRequest(); req.setRole(GridRole.NODE); Map nodeConfiguration = new HashMap(); nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, DefaultRemoteProxy.class.getName()); nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 5); nodeConfiguration.put(RegistrationRequest.PORT, 5555); nodeConfiguration.put(RegistrationRequest.HOST, 4444); nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true); nodeConfiguration.put(RegistrationRequest.REGISTER_CYCLE, 5000); nodeConfiguration.put(RegistrationRequest.HUB_HOST, “localhost”); nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444); nodeConfiguration.put(“remoteHost”, “http://” + strIP + […]