Tag: webdriver

使用selenium时如何处理Windows文件上传窗口

我正在尝试使用java为网站编写selenium测试。 但是,我在测试文件上传时遇到了一个问题。 当我单击文件上传按钮时,它会自动打开Windows文件上传。 我有代码工作将文本成功地放在上传框中,只是我没有办法阻止Windows框自动启动,并且让网站不自动打开Windows文件上传并不是一个真正的选择。 通过研究这个主题,我知道selenium webdriver无法处理这个问题。 所以我的问题是:我可以通过自动方式关闭上传窗口的方式是什么? 我已经尝试过java机器人类,但它没有用。 它等到上传窗口关闭之后再执行我给它的任何命令(ALT-F4,点击xy位置等) 提前致谢 编辑: wait.until(ExpectedConditions.elementToBeClickable(By.id((“addResourcesButton”)))); driver.findElement(By.id(“addResourcesButton”)).click(); //popup window comes up automatically at this point try { Robot robot = new Robot(); robot.mouseMove(875, 625); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); } catch (AWTException e) { e.printStackTrace(); } //my attempt to move the mouse and click, doesn’t move or click until after I close […]

在PATH中找不到firefox二进制文件。 确保安装了firefox。 操作系统似乎是:VISTA

我无法在任何浏览器中运行我的脚本。 下面是我得到的firefox错误。 firefox的安装位置是正确的。 不知道出了什么问题。 我正在使用Firefox 15. Selenium Java 2.2.0和Eclipse Juno 我的测试用例如下: import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class FirstTest { private WebDriver _driver; @Before public void setUp() throws Exception { System.setProperty(“webdriver.firefox.driver”,”C:\\Program Files\\Mozilla Firefox15\\Firefox.exe”); FirefoxProfile firefoxProfile = new FirefoxProfile(); _driver = new FirefoxDriver(firefoxProfile); } […]

加载页面后,selenium获取当前URL

我在Java中使用Selenium Webdriver。 我想在点击“下一步”按钮后从第1页到第2页获取当前url。这是我的代码: WebDriver driver = new FirefoxDriver(); String startURL = //a starting url; String currentURL = null; WebDriverWait wait = new WebDriverWait(driver, 10); foo(driver,startURL); /* go to next page */ if(driver.findElement(By.xpath(“//*[@id=’someID’]”)).isDisplayed()){ driver.findElement(By.xpath(“//*[@id=’someID’]”)).click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[@id=’someID’]”))); currentURL = driver.getCurrentUrl(); System.out.println(currentURL); } 在获取当前url之前,我有隐式和显式等待调用等待页面完全加载。 但是,它仍然打印出第1页的url(预计它将成为第2页的url)。

带有Java的Selenium Webdriver:在缓存中找不到元素 – 也许页面在查找后已经发生了变化

我在我的课程开头初始化一个变量: public WebElement logout; 稍后在代码中,在某些方法中,第一次遇到注销按钮时,我为该变量赋值(在if / else语句的括号中): logout = driver.findElement(By.linkText(“Logout”)); logout.click(); 然后,我在测试的另一个阶段成功地再次使用“logout”: logout.click(); 在测试结束时,在元素相同的地方(By.linkText(“Logout”)),我收到此错误: Element not found in the cache – perhaps the page has changed since it was looked up 为什么? 编辑:实际上,我没有成功使用logout.click(); 在我测试的另一个阶段。 看起来我不能再使用它了。 我必须创建一个logout1 webelement并使用它…

如何检查来自浏览器的待处理请求(Ajax及其变体)

我处理的一些网站有很多ajax请求。 我打算在点击断言元素之前等待Ajax请求完成。 目前我用 try { if (driver instanceof JavascriptExecutor) { JavascriptExecutor jsDriver = (JavascriptExecutor)driver; for (int i = 0; i< timeoutInSeconds; i++) { Object numberOfAjaxConnections = jsDriver.executeScript("return jQuery.active"); // return should be a number if (numberOfAjaxConnections instanceof Long) { Long n = (Long)numberOfAjaxConnections; System.out.println("Number of active jquery ajax calls: " + n); if (n.longValue() == […]

将Chrome驱动程序与Selenium 2配合使用

我正在尝试使用Chrome Drive执行我的一些测试,这些测试与Firefox完美配合,但我无法执行它们,我已经validation了要求,这是Chrome的位置,版本12或更高,以及类似的东西,但无论如何仍然无法正常工作,调用驱动程序的方式是: WebDriver fd = new ChromeDriver(); fd.get(“url”); 然后搜索一些元素,但没有任何工作,错误消息是: 线程“main”中的exceptionorg.openqa.selenium.WebDriverException:找不到Chrome。 设置webdriver.chrome.bin系统信息:os.name:’Windows XP’,os.arch:’x86’,os.version:’5.1’,java.version:’1.6.0_18’驱动程序信息:driver.version: ChromeDriver位于org.openqa.selenium.chrome.ChromeBinary.getChromeBinaryLocation(ChromeBinary.java:220)org.openqa.selenium.chrome.ChromeBinary.getCommandline(ChromeBinary.java:121)org.openqa.selenium.chrome.ChromeBinary。在org.openqa的org.openqa.selenium.chrome.ChromeBinary.start(ChromeBinary.java:109)org.openqa.selenium.chrome.ChromeCommandExecutor.start(ChromeCommandExecutor.java:373)的prepareProcess(ChromeBinary.java:67)位于org.openqa.selenium.chrome.ChromeDriver的org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:85).selenium.chrome.ChromeDriver.startClient(ChromeDriver.java:65)。(ChromeDriver.java:25 )org.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:43)atg.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:53)at equifax.qa.test.NewTests.access.main( access.java:11) 如果有人能帮助我,那就太好了。

WebDriver:如何检查页面对象Web元素是否存在?

使用带有webdriver的页面对象时,如何检查元素是否存在。 到目前为止,我这样做。 DefaultPage defaultPage = PageFactory.initElements(this.driver, DefaultPage.class); assertTrue(defaultPage.isUserCreateMenuLinkPresent()); 页面对象: public class DefaultPage { @FindBy(id = “link_i_user_create”) private WebElement userCreateMenuLink; public boolean isUserCreateMenuLinkPresent() { try { this.userCreateMenuLink.getTagName(); return true; } catch (NoSuchElementException e) { return false; } } } 但我无法相信这种尝试/捕获是人们应该这样做的方式。 那么什么是更好的方法来检查元素是否退出(使用页面对象)?

使用Selenium WebDriver和Java滚动

我正在使用Selenium WebDriver自动化我的浏览器测试。 我的浏览器标题是浮动的,无论浏览器滚动如何,它总是存在 。 因此,当我单击浏览器当前可见区域下方的某些元素时,selenium会尝试将元素滚动到视图中并单击它们。 但是由于自动滚动,因此元素在浮动标题后面滚动,当对它们执行任何操作时,页面标题中的元素被单击。 有没有办法限制WebDriver的默认滚动 ?

在selenium自动化期间绕过“外部协议请求”弹出窗口

我在mac和ubunto上运行自动化(使用黄瓜,selenium网络驱动程序,junit) 在自动化过程中,我单击一个非http协议的链接 出现“外部协议请求”弹出窗口。 它阻止我的测试测试网页的其余部分。 我怎样才能轻易绕过它? 我想也许可以编写一个什么也不做的jar然后将它注册到这个外部协议,但是这个弹出窗口仍然会出现,但它无济于事。 也许使用其他浏览器可以帮助? 还有其他建议吗?

使用无头浏览器进行调试

我有一个WebDriver测试套件,当我在普通和无头浏览器中执行它时,它运行不同。 当我在无头模式下执行它时,找不到一个元素,但是当我在正常模式下使用相同的代码,相同的驱动程序时,会发现该元素。 我用这个标志来设置无头模式: chromeOptions.addArguments(“–headless”); 正在使用ChromeDriver 2.31和WebDriver 3.5.2 。 我怎么调试这个?