Tag: selenium

如何使用Java关闭Selenium WebDriver中的子浏览器窗口

很长一段时间我在这里遇到了一些问题。 我无法弄清楚,有人愿意帮助我吗? …当我要完成新窗口的任务后,我要切换新窗口。 我想关闭那个新窗口。切换旧窗口, 所以这里我写的代码如下: // 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”); […]

wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)

我想使用wait.until(ExpectedConditions)和TWO元素。 我正在运行测试,我需要WebDriver等待,直到Element1或Element2中的任何一个出现。 然后我需要选择先出现的人。 我试过了: WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//h2[@class=’….’]”))) || wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//h3[@class=’… ‘]”))); // Then I would need: String result = driver.findElement(By.xpath(“…”)).getText() || driver.findElement(By.xpath(“…”)).getText(); 总而言之,我需要等到两个元素中的任何一个出现。 然后挑选出现的人(他们不能同时出现)请帮助。

Webdriver – HTTP身份validation对话框

我有一个非常简单的selenium-webdriver脚本。 我想使用webdriver进行HTTP身份validation。 脚本: WebDriver driver = new FirefoxDriver(); driver.get(“http://www.httpwatch.com/httpgallery/authentication/”); driver.findElement(By.id(“displayImage”)).click(); Thread.sleep(2000); driver.switchTo().alert().sendKeys(“httpwatch”); 问题: driver.switchTo().alert().sendKeys(“httpwatch”); 投 org.openqa.selenium.NoAlertPresentException:不存在警报 题: Webdriver是否仅查找警报对话框作为警报? 如果不使用AutoIt或http:// username:password @somesite,我可以选择自动执行此操作 编辑 警报有以下方法,似乎尚未实施。 driver.switchTo().alert().authenticateUsing(new UsernameAndPassword(“username”,”password”))

如何让Firefox在Mac OSX上使用Selenium WebDriver

我正在尝试为WebDriver配置代理设置,所以我使用了以下代码…. FirefoxProfile profile = new FirefoxProfile(); profile.setPreference(“network.proxy.type”, 1); profile.setPreference(“network.proxy.http”,”207.229.122.162″); profile.setPreference(“network.proxy.http_port”, 3128); WebDriver driver = new FirefoxDriver(profile); selenium = new WebDriverBackedSelenium(driver, “http://www.example.com/”); 并且在对文件执行运行后,我得到例外… org.openqa.selenium.WebDriverException:在PATH中找不到firefox二进制文件。 确保安装了firefox。 操作系统似乎是:MAC 系统信息:os.name:’Mac OS X’,os.arch:’x86_64’,os.version:’10 .6.8’, java.version:’1.6.0_29′ 驱动程序信息:driver.version:FirefoxDriver 任何人都可以帮我解决如何以及在哪里给firefoxprofile()路径

Selenium / Firefox:命令“.click()”不适用于找到的元素

我试图找到解决这个问题的方法,我花了很多时间,但这对我来说几乎是不可能的。 问题:我在Firefox中使用Selenium和Java。 我需要找到一个元素(列表框)并单击它。 因此,代码找到元素,但单击操作不起作用。 它每次都适用于谷歌浏览器,有时只在Firefox中(有时相同的Java代码有效,有时则无效)。 当程序进入页面时,有一部分代码带有元素: SELECCIONA TALLA Guía de tallas 并且在单击元素时,代码的一部分会发生变化: 我尝试了很多解决方案,有时它可以工作,但下次我运行程序时,它不再起作用。 一些解决方案 它找到元素,但不运行单击操作。 我检查了xpath和cssSelector,并且找到了这些表达式的唯一元素。 driver.findElement(By.xpath(“//div[@id=’size-btn’ and not(contains(@class,’opened’))]/span”)).click(); // Also checked with By.cssSelector(“span.selected-size”) 我虽然是因为时间,所以我试图以这种方式解决它。 WebElement we = driver.findElement(By.xpath(“//div[@id=’size-btn’ and not(contains(@class,’opened’))]/span”)); // By.cssSelector(“span.selected-size”) Thread.sleep(3000); we.click(); 最后,我有点绝望,我创建了一个新function,尝试这样做了近60次,寻找元素代码的更改,如果有任何更改,只是尝试再次单击操作。 clickAndWaitWhileElementIsNotPresent(By.xpath(“//div[@id=’size-btn’ and not(contains(@class,’opened’))]/span”),By.xpath(“//div[@class=’size-btn opened’]/span”)); // By.cssSelector(“span.selected-size”) private void clickAndWaitWhileElementIsNotPresent(By by1, By by2) throws Exception { for (int second = […]

如何使用java实现与Selenium WebDriver的PhantomJS

我真的很生气。 我有这个代码: public class Creazione extends TestCase { private PhantomJSDriver driver; private String baseUrl; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { File file = new File(“C:/Program Files/phantomjs-1.9.7-windows/phantomjs.exe”); System.setProperty(“phantomjs.binary.path”, file.getAbsolutePath()); driver = new PhantomJSDriver(); baseUrl = “http://www.gts.fiorentina.test/”; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(baseUrl + “/Account/Login.aspx?ReturnUrl=%2f”); findDynamicElement(By.id(“tbUserName_I”), 2000); driver.findElement(By.id(“tbUserName_I”)).clear(); […]

如何在Selenium WebDriver中选择日期选择器

目前正在使用Selenium WebDriver并使用Java 。 我想从下拉列表中选择date range值。我想知道如何在日期选择器下拉列表中选择Date, Month and year值。 这是HTML标记: 我试过以下示例代码: Log.info(“Clicking on From daterange dropdown”); JavascriptExecutor executor8 = (JavascriptExecutor)driver; executor8.executeScript(“document.getElementById(‘fromDate’).style.display=’block’;”); Select select8 = new Select(driver.findElement(By.id(“fromDate”))); select8.selectByVisibleText(“10 Jan 2013”); Thread.sleep(3000); Log.info(“Clicking on To daterange dropdown”); JavascriptExecutor executor10 = (JavascriptExecutor)driver; executor10.executeScript(“document.getElementById(‘toDate’).style.display=’block’;”); Select select10 = new Select(driver.findElement(By.id(“toDate”))); select10.selectByVisibleText(“31 Dec 2013”); Thread.sleep(3000);

如何使用Selenium WebDriver与Java向下滚动

我想向下滚动我的网页,并使用此代码滚动页面,但它无法正常工作 public ViewBasketSentToMePageObject viewSlideShare() throws InterruptedException { Thread.sleep(500l); Actions action1 =new Actions(getDriver()); action1.keyDown(Keys.CONTROL).sendKeys(String.valueOf(‘\u0030′)).build().perform(); List function = getDriver().findElements(By.xpath(“//a [@ng-click=’onItemClick()’]”)); function.get(13).findElement(By.xpath(“//img [@ng-src=’resources/images/slideshare-icon-small.png’]”)).click(); return getFactory().create(ViewBasketSentToMePageObject.class); } 寻求帮助

使用java的空间webdriver类名

这个问题在jquery中得到了很好的答案,我想知道是否有人可以在Java中给出一个这样的例子吗? 我正在做driver.findElement(By.className(“current time”)).click(); 空间是问题,我在链接上看到了解释,但我不确定如何在java中处理它,并且无权更改类名。 粘贴我在Firefox中检查id的示例:下面的cssSelector示例不起作用,但我可能会遗漏一些东西。 url

Selenium是Web UI测试,因为________是Windows应用程序UI测试

我对仅测试客户端Java应用程序的UI感兴趣。 这样做最流行的框架是什么? 你推荐的框架是什么? 另外,为什么Selenium不这样做(或者是这样做)? 在我看来,任何可以测试Web应用程序的东西都应该能够测试Windows应用程序。