zwwcn

Just another WordPress.com site

Category Archives: Selenium

simulate signature in selenium

the following code simulate signature on canvas:

Actions builder = new Actions(getDriver());
WebElement canvasElement = getDriver().findElement(By.id("cordova.signature-view:pad"));
Action drawAction = builder.moveToElement(canvasElement, 20, 20)
	.clickAndHold()
	.moveByOffset(80, 80)
	.moveByOffset(50, 20)
	.release()
	.build();
drawAction.perform();

maximize window for selenium webdriver

Toolkit toolkit = Toolkit.getDefaultToolkit();

Dimension screenResolution = new Dimension((int) toolkit.getScreenSize().getWidth(), (int) toolkit.getScreenSize().getHeight());

driver.manage().window().setSize(screenResolution);

Upgrade to Selenium2

1 click a button  in picklist:

By default, define a webelement will perform click operation.
here we need to get focus for the current browser, then click the button.
getDriver().findElement(By.id(id)).findElement(By.xpath(“..”)).click();
WebElement selectElement = getDriver().findElement(By.id(id));

------------------------------ 

Selenium1

table clickLinkInCell : id is the id for the link

mytempaltesPage.contentTemplatesTable.clickLinkInCell(inactiveEmailrow, “titleLink”, EditContentTemplatePage.class);

 

getCellText: id is the id for the collumn

contentTemplatesTable.getCellText(rowIndex, “title”);

 

 

fireblureevent: ajax call

wait ajax redering the page

invoicePage.invoiceItemTable.getPrice(0).type(“1.00”);
invoicePage.invoiceItemTable.getPrice(0).fireBlurEvent();
invoicePage.invoiceItemTable.getPrice(0).waitFor(2000);

Selenium exception: element is undefined

avoid to read the same field twice

replace

Assert.assertEquals(“expected  Windscreen Servicing got ” + leadpage.leadList.getEvent(0)   , “Windscreen Servicing” , leadpage.leadList.getEvent(0));

with

String event = leadpage.leadList.getEvent(0);

Assert.assertEquals(“expected  Windscreen Servicing got ” + event   , “Windscreen Servicing” ,event);