Tag: webdriver

使用Selenium的Chrome驱动程序:“找不到适合RemoteWebDriver的构造函数”

我正在尝试在java绑定下使用带有Selenium的chrome驱动程序。 我按照以下说明操作: ChromeDriver说明 所以我运行ChromeDriver.exe,把它放在我的代码WebDriver driver = new RemoteWebDriver(“http://localhost:9515”, DesiredCapabilities.chrome()); 我收到此错误: Error:(33, 28) java: no suitable constructor found for RemoteWebDriver(java.lang.String,org.openqa.selenium.remote.DesiredCapabilities) constructor org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor,org.openqa.selenium.Capabilities) is not applicable (argument mismatch; java.lang.String cannot be converted to org.openqa.selenium.remote.CommandExecutor) constructor org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(java.net.URL,org.openqa.selenium.Capabilities) is not applicable (argument mismatch; java.lang.String cannot be converted to java.net.URL) 如何让Chrome驱动程序工作? 编辑:使用其他方法: System.setProperty(“webdriver.chrome.driver”, “PATH\\chromedriver.exe”); WebDriver driver = new ChromeDriver(); 我收到这些错误: […]

Selenium Web驱动程序:findElement(By.name …和无头浏览器

我正在尝试遵循Selenium Webdrive教程 http://www.toolsqa.com/selenium-webdriver/headless-browser-testing-selenium-webdriver/ 有一个简单的测试,这里是你的步骤: 打开网页http://google.com 获取页面标题。 搜索’Selenium’ 再次检查页面标题。 从类代码示例开始,这里是您的代码 package headlessBrowser; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class TestOne { public static void main(String[] args) { // Declaring and initialising the HtmlUnitWebDriver HtmlUnitDriver unitDriver = new HtmlUnitDriver(); // open google.com webpage unitDriver.get(“http://google.com”); System.out.println(“Title of the page is -> ” + unitDriver.getTitle()); // find the […]

WebDriver无法使用Java通过xpath找到元素

以下是使用Java的WebDriver代码片段: WebDriver driver = new FirefoxDriver(); driver.get(“http://www.google.pl/”); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebElement element = driver.findElement(By.name(“q”)); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebElement query = driver.findElement(By.xpath(“//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input”)); query.sendKeys(“asd”); 执行代码后,我得到以下exception: 线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法定位元素:{“method”:“xpath”,“selector”:“// html / body / div [2] / span / center / form / table / tbody / tr / td [2] / div / div / input“}系统信息:os.name:’Windows 7’,os.arch:’x86’,os.version:’6.1’,java.version: ‘1.6.0_24’驱动程序信息:driver.version:sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)中的sun.reflect.NativeConstructorAccessorImpl.newInstance(未知来源)位于sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知来源)处的RemoteWebDriver org.openqa.selenium.remote上的org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)中的java.lang.reflect.Constructor.newInstance(未知来源).ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105 )org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409)org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:192)at org.openqa.selenium.remote.RemoteWebDri ver.findElementByXPath(RemoteWebDriver.java:265)atg.openqa.selenium.By […]

如何在网页中的特定div中垂直向下滚动

我搜索了所有的论坛,但我没有得到正确的答案。 我要测试的网页下面隐藏了一个链接,我试图通过使用xpath或元素的ID属性搜索它来手动找到它,但是当我运行Web驱动程序脚本时,我无法找到它。 即使它没有在该元素上给出任何错误,我在下一个命令/行上收到错误。 我从论坛中找到了以下代码,这是滚动整个页面。 我不想这样,我想在屏幕截图中垂直向下滚动特定div区域。 JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript(“ctl00_Menu1_scrollDiv.scrollBy(0,250)”, “”); div id for this is “ctl00_Menu1_scrollDiv” Element id: ctl00_Menu1_DlMenu_ctl09_LnkMenuname 请帮我解决这个问题。 提前致谢。 帮助将不胜感激。

如何在selenium上传多个文件?

我正在尝试使用以下代码: – driver.findElement(By.xpath(“.//*[@id=’attach0′]”)).sendKeys(“first path”+”\n”+”second path””+”\n”third path”); 我没有得到结果 请帮我!

Selenium WebDriver – Java – 单击按钮

我正在尝试点击一些按钮,我正在使用twitch上的Follow按钮作为示例。 我使用Selenium IDE尝试获取按钮的xpath。 我得到的xpath是: //span[@id=’ember637′]/a/span 如果我去FireFox并为按钮复制唯一选择器我得到: .js-follow > span:nth-child(1) 我已经在java程序中尝试过它们并且它们不起作用。 当我使用//span[.. xpath时,我收到以下错误: “Unable to locate a node using //span[@id=’ember637′]/a/span” 编辑: 带有我想点击的按钮的网站示例(“关注”按钮): http : //www.twitch.tv/mradder89/profile/ 我正在使用的Selenium jar文件是“selenium-server-standalone-2.35.0.jar” 我得到的错误是 “Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate a node using //span[@id=’ember637′]/a/span” 编辑2: 我下载了PhantomJSDriver exe文件(phantomjs.exe)并试用了它。 它不起作用…我没有像以前那样得到错误消息(“无法找到节点…”错误)。 这是代码: http : //pastebin.com/GzvubMZr

如何通过selenium-webdriver和Java使用java鼠标hover

在尝试自动化门户网站http://demo.nopcommerce.com/时 ,无法选择鼠标hover在“Electornics”菜单上并选择“相机和照片”子菜单。 使用下面的脚本也是如此。 WebElement electronic_Pdts = driver.findElement(By.xpath(“//*[@class=’title’]//*[@title=’Show products in category Electronics’]”)); action.moveToElement(electronic_Pdts).build().perform(); driver.findElement(By.xpath(“//*[@src=’http://sofzh.miximages.com/java/0000006_camera-photo_450.jpg’]”)).click();

如何检查100%覆盖的WebElement是否可以与Selenium一起点击

我有两个具有绝对位置的div Visible later To be removed 和一些Javascript(这里没有显示)从DOM中删除4712一段时间(比如说2秒后)。 现在,在我的Selenium测试中,我想检查4711是否可点击。 从用户的角度来看,只有在删除4712后才能点击它。 所以我试过了 new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id(“4711”))); 但是,4711始终是可点击的(启用=真,显示=真),即使在删除4712之前也是如此。 有没有办法如何检查4711是否真的可以点击,也就是说,从用户的角度可以点击(理想情况下不使用Javascript)?

Selenium – 存储会话数据

我在整个互联网上搜索,但我找到的答案都没有明确的解决方案。 我正在使用selenium webdriver和Java。 我的测试需要validation您何时保存登录信息并关闭浏览器并重新打开它,然后这些凭据保留并保存在新会话中。 因此,我想关闭当前会话并重新打开它以validationcookie是否仍然存在于页面上,但Selenium会删除所有存储的会话数据,因此测试用例将始终失败。 有没有办法阻止Selenium在关闭特定测试用例的浏览器后删除存储的会话数据? 当我运行它时,我得到一个没有这样的会话错误。

使用Seleniumvalidation之间的文本

我需要validation网页上的特定插槽是否已加载。 我在main()函数中使用Selenium WebDriver(我应该使用JUnit测试用例吗?)。 在具有特定ID的任何 之间检索文本的方法有哪些? 如果给出此页面 : Make money by Selling items on Amazon Selling On Amazon Sell your items on Amazon.com. Amazon can help you grow your business and reach more customers. 当给出 ,我需要提取 “通过在亚马逊上销售商品来赚钱”, “在亚马逊上卖”, “在Amazon.com上销售您的商品。亚马逊可以帮助您拓展业务并吸引更多客户。” 我应该使用哪种方法?