Tag: webdriver

Selenium Webdriver 3.0.1:Selenium显示FluentWait类的错误

我正在使用Selenium Standalone Server 3.0.1 。 我试图向我的代码添加Explicit Wait以便在元素变得可见时通过xpath检测元素。 为了获得一些Java帮助,我查找了Selenium Standalone Server 3.0.1的源代码,但无法找到它。 我在selenium-java-2.53.1版本中找到了源代码。 我下载了它,找到了selenium-java-2.53.1-srcs并添加到我的Eclipse IDE 。 在FluentWait的帮助下,我只需复制粘贴Eclipse IDE的代码并更改变量名称。 文档中的示例代码如下: // Waiting 30 seconds for an element to be present on the page, checking // for its presence once every 5 seconds. Wait wait = new FluentWait(driver) .withTimeout(30, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function() […]

保持用户登录 – 使用Web驱动程序保存cookie

这就是我想用WebDriver执行的操作。 使用选中的复选框登录该站点,保持用户登录。 关闭浏览器。 再次转到该站点并确保该用户已登录。 问题是当我关闭驱动程序并重新打开它时,我没有登录。 我的代码看起来像这样 – WebDriver myD = null; myD = new FirefoxDriver(); String URL = “https://www.eurostylelighting.com/protected/account/signin?ReturnUrl=%2f”; myD.navigate().to(URL); myD.findElement(By.cssSelector(“input#txtEmailorRewards”)).sendKeys(“abc@yahoo.com”); myD.findElement(By.cssSelector(“input#txtPassword”)).sendKeys(“abc”); myD.findElement(By.xpath(“.//*[@id=’accountSignIn’]/dl[4]/dd/label/span”)).click(); Set cookies = myD.manage().getCookies(); myD.close(); myD= new FirefoxDriver(); myD.navigate().to(URL); for(Cookie getCookie:cookies) myD.manage().addCookie(getCookie);

如何在C#中使用WebDriver获取指定元素的屏幕截图

我的小项目是用Java编写的,我需要用C#重写它。 它差不多完成了,但我仍然坚持使用Selenium webdriver获取元素的截图。 我用下一种方式在Java中做到了: public String saveImage(){ String src = “”; try{ File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); BufferedImage fullImg = ImageIO.read(screenshot); Point point = elementToScreent.getLocation(); int eleWidth = elementToScreent.getSize().getWidth(); int eleHeight = elementToScreent.getSize().getHeight(); BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight); ImageIO.write(eleScreenshot, “png”, screenshot); src = path + System.currentTimeMillis() +”.png”; FileUtils.copyFile(screenshot, new File(src)); }catch(Exception e){ e.printstacktrace(); } return […]

如何使用Selenium Webdriver处理浏览器级别的通知

我使用Selenium Webdriver和核心Java自动化一些测试用例,在Chrome浏览器中点击一个测试用例点击按钮我得到浏览器级别通知’显示带有选项允许和阻止的通知’。 我想选择允许选项。 谁能知道如何使用Selenium webdriver处理这种通知。 请参阅以下快照了解更多详情

Selenium自动接受警报

有谁知道如何禁用它? 或者如何从已自动接受的警报中获取文本? 这段代码需要工作, driver.findElement(By.xpath(“//button[text() = \”Edit\”]”)).click();//causes page to alert() something Alert alert = driver.switchTo().alert(); alert.accept(); return alert.getText(); 但反而给出了这个错误 No alert is present (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 2.14 seconds 我正在使用FF 20和Selenium 2.32

使用Selenium ChromeDriver设置Chrome的语言

我下载了ChromeDriver,默认情况下浏览器语言是英文的,我需要将其更改为西class牙语,我一直无法使用。 public WebDriver getDriver(String locale){ System.setProperty(“webdriver.chrome.driver”, “driver/chromedriver.exe”); return new ChromeDriver(); } public void initializeSelenium() throws Exception{ driver = getDriver(“en-us”) }

Selenium UnreachableBrowserException – SoapUI中的“无法启动新会话”Groovy TestStep

我在Win7 x32上使用SoapUI Pro 5.1.2,并尝试在Groovy TestStep中连接到Selenium Webdriver。 为此,我在$SOAP_HOME$\bin\ext文件夹中添加了selenium-standalone-server.jar v2.45.0。 我的Groovy TestStep代码: import org.openqa.selenium.WebDriver import org.openqa.selenium.chrome.ChromeDriver System.setProperty(‘webdriver.chrome.driver’, ‘C:\\\\Windows\\system32\\chromedriver.exe’) log.info(System.getProperty(‘webdriver.chrome.driver’)) //got ‘C:\\Windows\system32\chromedriver.exe’ WebDriver driver = new ChromeDriver() // this line causes error driver.get(‘http://google.com’) driver.quit() 当我尝试运行此步骤时,SoapUI返回消息: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: […]

在Webdriver中使用个人SSL证书(Selenium 2.0)

我正在测试一个需要个人SSL证书的网站才能做某些事情,比如登录。 我有一个使用代理设置的Webdriver(Selenium 2.0)测试: Proxy localhostProxy = new Proxy(); localhostProxy.setProxyType(Proxy.ProxyType.MANUAL); localhostProxy.setHttpProxy(“www-proxyname:port”); FirefoxProfile profile = new FirefoxProfile(); profile.setProxyPreferences(localhostProxy); driver = new FirefoxDriver(profile); 这将很好地访问主页。 然后,测试点击登录按钮,输入正确的凭据并单击提交。 此时浏览器进入加载状态,我假设是因为我的身边缺少SSL证书,因此无法连接到登录服务。 我搜索了不同的代理解决方案,发现了这个: profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(true); 所以我把它添加到我的代码中,但它似乎没有做我想要的。 我想我正在寻找一种方法告诉WebDriver我的ssl证书在x目录中,请在访问此站点时使用它。 有谁知道如何做到这一点? 我的测试代码是: @Test public void userSignsInAndVerifiesDrawerViews(){ driver.get(“www.url.com”); waitFor(5000); driver.findElement(By.xpath(“//a[contains(text(), ‘Sign in’)]”)).click(); waitFor(3000); String username = “seleniumtest”; String password = “seleniumtest1”; driver.findElement(By.id(“username”)).sendKeys(username); driver.findElement(By.id(“password”)).sendKeys(password); driver.findElement(By.xpath(“//signin”)).click(); waitFor(30000); String signInLinkText = […]

如何使用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”); […]

如何让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()路径