get()和navigate()方法有什么区别? 这个或者其他方法是否等待页面内容加载? 我真正需要什么是像seleniums 1.0 WaitForPageToLoad, but for using via webdriver` but for using via 。 有什么build议么?
我使用Selenium WebDriver(Java)和TestNG在我创build的网站上进行一些testing。 在这个网站中,我也有JavaScript,在一些函数中,它通过console.log()函数返回值并将值输出到浏览器控制台。 我想知道是否有一个简单的方法让Selenium WebDriver访问这些JavaScript信息,以便我可以使用TestNG执行断言。 我对selenium很新,但我知道你可以做这样的事情: WebDriver driver = new ChromeDriver(); driver.findElement(By.id("btn")).click(); 那么有没有什么类似的,我可以使用WebDriver来读取网站上的JavaScript? 澄清 看起来人们正在假设我正试图通过Selenium“执行”JavaScript代码。 事实并非如此。 相反,我试图使用Selenium存储已定义的JavaScriptvariables。 基本上,我希望Selenium能够获取JavaScriptvariables的值,将其存储在本地,然后对其进行断言testing。 尝试1 说我有我的网站的以下JS代码: $(document).ready(function() { var foo = $(#"input-field-val").val(); function returnFoo() { return foo; } }); 从我阅读和理解的东西,在我单独的Seleniumtesting文件(Selenium.java)中,我应该可以做这样的事情吗? public class Selenium { WebDriver driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor) driver; @Test public void testSample() { driver.get("www.mywebsite.com"); js.executeScript("alert(returnFoo());"); […]
我是量angular器新手,我试图实施e2etesting。 我不知道这是否是正确的方式来做到这一点,但是…我想testing的页面不是一个完整的angular度页面,所以…我有一些麻烦。 在我的第一个规范中,我有: describe('should open contact page', function() { var ptor = protractor.getInstance(); beforeEach(function(){ var Login = require('./util/Login'); new Login(ptor); }); 我已经创build了这个Login类,但login后我想打开联系页面,但量angular器立即尝试在页面完全加载之前find元素。 我试过使用: browser.driver.wait(function() { expect(browser.findElement(by.xpath("//a[@href='#/contacts']")).isDisplayed()); ptor.findElement(by.xpath("//a[@href='#/contacts']")).click(); }); 但它不工作…它总是试图find页面加载之前的元素。 我也试过这个: browser.driver.wait(function() { expect(ptor.isElementPresent(by.xpath("//a[@href='#/contacts']"))); ptor.findElement(by.xpath("//a[@href='#/contacts']")).click(); }); 我能够做到这一点使用browser.sleep(); 但我不认为这是一个好的select。 任何想法? 在我的login类中,我有: ptor.ignoreSynchronization = true; 在量angular器尝试点击它之前,如何等待这个@ @href='#/contacts ?
为什么我们不能在Selenium IDE中logging所有的testing用例,将它导出到Java / WebDriver并在Eclipse中使用WebDriver运行? 我需要一个清晰的解释,因为我非常困惑的使用WebDriver! 任何人都可以请解释为什么WebDriver的IDElogging脚本失败?
我正在尝试为我的networkingtestingselect一个选项。 一个例子可以在这里find: http : //www.tizag.com/phpT/examples/formex.php 除了select一个选项部分,一切都很好。 如何按价值或标签select一个选项? 我的代码: using OpenQA.Selenium.Firefox; using OpenQA.Selenium; using System.Collections.ObjectModel; using System.Text.RegularExpressions; using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices; class GoogleSuggest { static void Main() { IWebDriver driver = new FirefoxDriver(); //Notice navigation is slightly different than the Java version //This is because 'get' is a keyword in C# driver.Navigate().GoToUrl("http://www.tizag.com/phpT/examples/formex.php"); IWebElement query […]
当我执行下面的代码时: public static void main(String[] args) { try { FirefoxDriver driver = new FirefoxDriver(); driver.get("http:www.yahoo.com"); } catch (NoClassDefFoundError ex) { System.out.println("error: " + ex.getStackTrace()); } } 我正面临以下错误: 错误:[Ljava.lang.StackTraceElement; @ 80f4cb 线程“main”中的exceptionjava.lang.NoClassDefFoundError:com / google / common / base / Function 有人能帮我find解决办法或原因吗?
今天运行我的rspectesting,我得到了下面的错误,无论何时在testingtheres一个`page.execute_script'调用的地方。 Selenium::WebDriver::Error::JavascriptError: waiting for evaluate.js load failed # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:8360:in `r' # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:392:in `fxdriver.Timer.prototype.runWhenTrue/g' # [remote server] file:///tmp/webdriver-profile20130807-3105-fpynb7/extensions/fxdriver@googlecode.com/components/driver_component.js:386:in `fxdriver.Timer.prototype.setTimeout/<.notify' 在上面的path的/ resources目录(而不是组件)中有一个文件evaluate.js,就像在其他机器上一样。 这发生在从22更新到Firefox 23之后。我还没有能够回滚,以确认返回到22确实解决了这个问题,但是我相信这一切都改变了。 有没有其他人看到这个问题? 运行Kubuntu 12.04,水豚1.1.4,selenium-webdrivergem2.33.0 我试着更新水豚2.什么和selenium-webdriver 2.34.0,没有变化。
在WebDriver中,如果使用sendKeys,它会将我的string附加到字段中已经存在的值。 我无法使用clear()方法清除它,因为第二个我这样做,网页会抛出一个错误,说它必须在10到100之间。所以我不能清除它,否则会抛出一个错误我可以使用sendKeys放入新的值,如果我发送键,它只是附加到已经存在的值。 WebDriver中有什么可以让你覆盖该字段的值?
我正在使用Selenium来自动化testing。 我的应用程序专门使用IE浏览器,它不会在其他浏览器上工作。 码: import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class Test { public static void main(String[] args) { final String sUrl = "http://www.google.co.in/"; System.setProperty("webdriver.chrome.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe"); WebDriver oWebDriver = new InternetExplorerDriver(); oWebDriver.get(sUrl); WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); // Use name locator to identify the search input field. oSearchInputElem.sendKeys("Selenium 2"); WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[@name='btnG']")); oGoogleSearchBtn.click(); try […]
出于某种原因,当我在工作中运行我的testing时,浏览器是最大化的,但是当我在家里运行它时,只会打开宽度约为50%的浏览器窗口。 这会导致一些与向下滚动等不一致的情况,所以我最好能在每台运行testing的机器上打开一个相同大小的浏览器窗口。 什么是最好的方法来做到这一点? (我发现其他语言的一些答案,但一直无法适应他们的JavaScript) 添加 browser.executeScript('window.moveTo(0,0);'+ 'window.resizeTo(screen.width, screen.height);'); 什么都不做,(显然window.moveTo和window.resizeTo不被铬支持)。