Tag: selenium webdriver

如何使用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); } 寻求帮助

如何使用Selenium WebDriver和Java获取选定的选项

我是Selenium的新手,我被困在这里: 我想使用Selenium WebDriver 获取 下拉列表 的选定标签或值,然后在控制台上打印 。 我可以从下拉列表中选择任何值,但我无法检索所选值并将其打印出来。 Select select = new Select(driver.findElement(By.id(“MyDropDown”))).selectByVisibleText(data[11].substring(1 , data[11].length()-1)); WebElement option = select.getFirstSelectedOption(); 但我所有的努力都是徒劳的任何帮助都将受到赞赏。 提前致谢 :)

如果已加载所需元素,请使Selenium Webdriver停止加载页面?

我正在创建一个测试并遇到一些问题。 这是场景。 我使用Selenium Web驱动程序在Page1上填写表单,然后单击按钮提交表单。 第2页开始加载…但问题是,Page2使用Google Analytics代码,有时页面停止加载需要一整年。 即使预期的元素已经存在,Selenium Web驱动程序也不会继续,直到整个网页完全加载。 如果预期元素已存在,如何让Selenium继续下一个任务或停止加载外部javascript / css? 我尝试调整以下设置但没有运气。 driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 临时解决方案:滚动下面的答案!

如何在文本框中找到并键入内容

public class testFluent { WebDriver driver; @Before public void setUp(){ driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().deleteAllCookies();} @Test public void myFirstFluent(){ WebElement element; driver.get(“http://www.yahoo.com”); element = myDynamicElement(By.id(“//*[@id=’p_13838465-p’]”)); System.out.println(“Element found”); } public WebElement myDynamicElement(final By locator){ Wait wait = new FluentWait(driver) .withTimeout(10, TimeUnit.SECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement element = wait.until(new Function(){ public WebElement apply(WebDriver drv){ return drv.findElement(By.id(locator)); […]

NoClassDefFoundError:Selenium for ChromeDriver中的org / apache / http / HttpEntity?

当我尝试从该网站访问数据时,我正试图从使用Selenium自动化的网站获取数据 run: Starting ChromeDriver (v2.9.248315) on port 15621 Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/http/entity/ContentType at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.(HttpCommandExecutor.java:411) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:306) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240) at org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:181) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:160) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:149) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:106) at pocmandi.PocMandi.main(PocMandi.java:32) Caused by: java.lang.ClassNotFoundException: org.apache.http.entity.ContentType at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) […]

如何在Selenium WebDriver(Selenium 2)中运行Firebug?

在运行Selenium 2时,在Firefox中激活Firebug的最佳方法是什么? 编辑:好的,我意识到“最佳”是开放的解释,但基于配置文件的解决方案真的曾经是selenium 1.0的痛苦。 所以任何替代方案都被认为更好,直到certificate更糟;

无法在Eclipse-Kepler中安装TestNG

当我尝试在我的VM(虚拟机)上安装TestNG时收到错误“无法在http://beust.com/eclipse/content.xml上读取存储库”。 “同行未经过身份validation” 我在网上尝试了很多解决方案,但没有运气。 任何人都可以帮我解决这个问题。 Eclipse版本:Kepler Service Release 1 Build id:20130919-0819 注意 :我没有VM上的Admin Privilege 谢谢,坎南

尝试打印链接名称时获取StaleElementReferenceException

我正在尝试打印谷歌搜索中显示的前5页链接..但是获取StateElementReferenceException不确定哪个出错了.. public class GoogleCoInTest { static WebDriver driver = null; public static void main(String[] args) throws InterruptedException { System.setProperty(“webdriver.gecko.driver”, “D:\\bala back up\\personel\\selenium\\Jars\\Drivers\\geckodriver.exe”); driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(“https://www.google.co.in/”); //driver.findElement(By.xpath(“//input[class=’gsfi’]”)).sendKeys(“Banduchode”);; WebElement search=driver.findElement(By.cssSelector(“input#lst-ib”)); search.sendKeys(“Banduchode”); search.sendKeys(Keys.ENTER); printLinksName(); List fiveLinks=driver.findElements(By.xpath(“.//*[@id=’nav’]/tbody/tr/td/a”)); for(int i=0;i<5;i++){ System.out.println(fiveLinks.get(i).getText()); fiveLinks.get(i).click(); Thread.sleep(5000); printLinksName(); } } public static void printLinksName() throws InterruptedException{ List allLinks=driver.findElements(By.xpath(“//*[@id=’rso’]/div/div/div/div/div/h3/a”)); System.out.println(allLinks.size()); //print all […]

检查Selenium Java中是否可以单击元素

我是Selenium新手,需要检查元素是否可以在Selenium Java点击,因为element.click()会在link和label上传递。 我尝试使用下面的代码,但没有工作: WebDriverWait wait = new WebDriverWait(Scenario1Test.driver, 10); if(wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“(//div[@id=’brandSlider’]/div[1]/div/div/div/img)[50]”)))==null) 需要帮助。

SessionNotCreatedException:无法创建新服务:在Ubuntu上使用Selenium Grid的GeckoDriverService无法驱动Firefox

我无法使用geckodriver从Selenium驱动Firefox。 这很奇怪,因为chrome使用相同的框架驱动而没有错误! 这些是我的版本号: Firefox 54.0 (64-bit) Chrome Version 62.0.3202.94 (Official Build) (64-bit) selenium-server-standalone-3.7.1.jar client-combined-3.5.3-nodeps.jar geckodriver-v0.19.1-linux64 chromedriver_linux64 Ubuntu 16.10 我从Selenium webdriver获得的错误如下: ——————————–Error: leder@leder-VirtualBox:~/Source/SeleniumCheese/bin$ ./execute_grid.sh Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’ System info: host: ‘leder-VirtualBox’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘4.8.0-59-generic’, java.version: […]