xpath=(//a[@class='addthis_button'])[last()-2]
xpath=(//a[@class='addthis_button'])[last()]
xpath=(//a[@class='addthis_button'])[position()=2]
//a[contains(@class, concat("addthis_button_compact", " at300m"))]
More reference : http://shanmugavelc.blogspot.com/2011/11/selenium-css-locators.html
Wednesday, April 11, 2012
Tuesday, February 14, 2012
Flash with selenium
Selenium/Webdriver cannot click on the flash application. Only thing it can do is invoke the functions defined in as3 scripts using javascript. For functions to be accessible to javascript it should be added to ExternalInterface. ExternalInterface is used to call javascript function from/to flash.
ExternalInterface.addCallback("setText", setText) makes setText method invokable from javascript
WebDriver driver = new FirefoxDriver();
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "");
driver.get("http://sitestress.webmetrics.com/test/flashtest.html");
selenium.getEval("var movie = window.document.extinterfaceexample; movie.jsToFlash('water in water');");
driver.get("http://bowser.effectgames.com/~jhuckaby/zeroclipboard/");
// selenium.type("fe_text", "bla bla bla");
selenium.getEval("var playerid = window.document.ZeroClipboardMovie_1; playerid.setText('james bond')");
For above example 'ZeroClipboardMovie_1' is the object id of the flash movie. It is used to create a variable for accessing the as3 functions.
For more details checkout Flash Selenium
ExternalInterface.addCallback("setText", setText) makes setText method invokable from javascript
WebDriver driver = new FirefoxDriver();
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "");
driver.get("http://sitestress.webmetrics.com/test/flashtest.html");
selenium.getEval("var movie = window.document.extinterfaceexample; movie.jsToFlash('water in water');");
driver.get("http://bowser.effectgames.com/~jhuckaby/zeroclipboard/");
// selenium.type("fe_text", "bla bla bla");
selenium.getEval("var playerid = window.document.ZeroClipboardMovie_1; playerid.setText('james bond')");
For above example 'ZeroClipboardMovie_1' is the object id of the flash movie. It is used to create a variable for accessing the as3 functions.
For more details checkout Flash Selenium
Tuesday, January 17, 2012
Auto it basics for entering text
Press escape key : Send("{ESCAPE}")
Press enter key : Send("{ENTER}")
Press tab key : Send("{TAB}")
Enter some content and press tab key : Send("water{TAB}")
Enter some content and press enter key : Send("water{ENTER}")
Press enter key : Send("{ENTER}")
Press tab key : Send("{TAB}")
Enter some content and press tab key : Send("water{TAB}")
Enter some content and press enter key : Send("water{ENTER}")
Autoit for File upload
Firefox
WinWaitActive("File Upload")
if WinExists("File Upload") Then
ControlSetText("File Upload", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("File Upload", "", "Button2")
EndIf
IE
WinWaitActive("Choose file")
if WinExists("Choose file") Then
ControlSetText("Choose file", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("Choose file" ,"", "Button2")
EndIf
Chrome
WinWaitActive("Open")
if WinExists("Open") Then
ControlSetText("Open", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(2000)
ControlClick("Open", "", "Button2")
EndIf
For more reference follow these links. These guys have given nice example
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium-with.html
http://iautomateit.wordpress.com/2011/07/15/working-around-file-upload-dialog-issues-with-selenium-2/
http://bharath-marrivada.blogspot.com/2011/02/selenium-autoitv3-file-upload-download.html
WinWaitActive("File Upload")
if WinExists("File Upload") Then
ControlSetText("File Upload", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("File Upload", "", "Button2")
EndIf
IE
WinWaitActive("Choose file")
if WinExists("Choose file") Then
ControlSetText("Choose file", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("Choose file" ,"", "Button2")
EndIf
Chrome
WinWaitActive("Open")
if WinExists("Open") Then
ControlSetText("Open", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(2000)
ControlClick("Open", "", "Button2")
EndIf
For more reference follow these links. These guys have given nice example
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium-with.html
http://iautomateit.wordpress.com/2011/07/15/working-around-file-upload-dialog-issues-with-selenium-2/
http://bharath-marrivada.blogspot.com/2011/02/selenium-autoitv3-file-upload-download.html
Thursday, January 12, 2012
FirefoxDriver with custom profile
Use profile manager to create profiles. In Windows machine profiles will be stored in the path
FirefoxProfile profile = new ProfilesIni().getProfile("profileName");
FirefoxDriver driver = new FirefoxDriver(profile);
Once firefox window opens check that addon's, bookmark etc are appearing in the newly opened firefox window.
C:\Documents and Settings\user\Application Data\Mozilla\Firefox\Profiles\
FirefoxProfile profile = new ProfilesIni().getProfile("profileName");
FirefoxDriver driver = new FirefoxDriver(profile);
Once firefox window opens check that addon's, bookmark etc are appearing in the newly opened firefox window.
Simulate click using javascript for webdriver
driver.get("http://www.google.com");
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement upload = driver.findElement(By.name("btnI"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement upload = driver.findElement(By.name("btnI"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);
By pass certificate validation failure in IE for https pages
if (driver instanceof InternetExplorerDriver)
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
Subscribe to:
Posts (Atom)