Skip to content

Instantly share code, notes, and snippets.

String originalHandle = driver.getWindowHandle();
driver.findElement(ElementsRelatorios.FORM_PDF).click();
Util.waitLoadingProgress();
for (String winHandle : driver.getWindowHandles()) {
if (!winHandle.equals(originalHandle)) {
driver.switchTo().window(winHandle);
}
}
System.out.println(driver.getCurrentUrl());
driver.close();
@jimevans
jimevans / code
Created April 27, 2012 21:14 — forked from sumxyz/gist:2513256
css selector help for selenium webdriver
for (int second = 0;; second++) {
if (second >= 60) {
fail("timeout");
}
try {
if (isElementPresent(By.cssSelector("#78089_title > li.deleteTitle.listDelete")))
break;
} catch (Exception e) {
System.out.println(e);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
@jimevans
jimevans / gist:4454253
Last active December 10, 2015 15:28 — forked from anonymous/gist:4454176
// Assumes TextBox is one of your "tag-specific" element classes.
// Could be RadioButton, or TableCell, or whatever the appropriate
// class is.
// Note that the TextBox class would probably have the MoveTo()
// method you're wanting.
public static TextBox Object1()
{
IWebElement object1 = driver.FindElement(By.Id("txtMyData"));
TextBox myTextBox = new TextBox(object1);
return myTextBox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA;
using Selenium.Controllers;
namespace Selenium.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA;
using Selenium.Controllers;
namespace Selenium.Controllers
{
public void GetPageRefresh()
{
new Actions(_myApp.Driver)
.KeyDown(Keys.Control).SendKeys("r")
.KeyUp(Keys.Control);
.Perform();
}
@jimevans
jimevans / gist:6257422
Last active December 21, 2015 05:29 — forked from anonymous/gist:6257421
public static int ClickNavigate(this IWebElement element, TimeSpan timeout)
{
int responseCode = 0;
string targetUrl = string.Empty;
SessionStateHandler responseHandler = delegate(Session targetSession)
{
// For the first session of the click, the URL should be the URL
// requested by the the element click.
if (string.IsNullOrEmpty(targetUrl))
{
public boolean isElementPresent(By by, int indexx) {
//driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
try {
driver.findElements(by).get(indexx);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
/*
error that i got:
java.lang.NullPointerException
at com.mycompany.PageGeneric.login(PageGeneric.java:36)
at com.mycompany.DemoPageFactory.loginTest(DemoPageFactory.java:41)
*/
//this is my page class
public class PageGeneric {
private WebDriver driver;