Академический Документы
Профессиональный Документы
Культура Документы
}
11) Select value from Dropdown
a) dropdownElement.selectByIndex()
b) dropdownElement.selectByValue()
c) dropdownElement.selectByVisibleText()
12) XPath
a) By.Xpath(“//tagname[@attributename=’value’]”)
b) By.Xpath(“//tagname[@attribute1=’value’ AND @attribute2=’value’]”)
c) By.Xpath(“//tagname[@attribute1=’value’ OR @attribute2=’value’]”)
d) By.Xpath(“//tagname[text()=’textofElement’]”)
e) By.Xpath(“//tagname[starts-with(@attributename,’value’)]”)
f) By.Xpath(“//tagname[starts-with(text(),’textoftag’)]”)
g) By.Xpath(“//tagname[contains(@attributename,’textOfElement’)]”)
h) By.Xpath(“//tagname[contains(text(),’textOfElement’)]”)
i) By.Xpath(“//tagname[ends-with(@attributname,’value’)]”)
j) By.Xpath(“//tagname[ends-with(text(),’vlaue’)]”)
k) By.Xpath(“//preceding-sibling::tagname[@attribute=’value’]”)
l) By.Xpath(“//following-sibling::tagname[@attribute=’value’]”)
m) By.Xpath(“//ancestor::tagname[@attribute=’value’]”)
n) By.Xpath(“..”) – immediate parent
13) Use of JavascriptExecutor
a) Click using JavascriptExecutor
WebElement aa= fDriver.findElement(By.xpath("//img[@src='images/frames_windows.jpg']"));
JavascriptExecutor executor = (JavascriptExecutor)fDriver;
executor.executeScript("arguments[0].click();", aa);
b) Sendkeys using JavascriptExecutor
WebElement searchbox = driver.findElement(By.xpath("//input[@name='q']"));
JavascriptExecutor myExecutor = ((JavascriptExecutor) driver);
myExecutor.executeScript("arguments[0].value='text to type in textbox';", searchbox);
14) Handling Alert popup
a) Click Cancel button
driver.switchTo().alert().dismiss();
b) Click OK button
driver.switchTo().alert().accept();
c) Get Alert popup message
driver.switchTo().alert().getText();
d) To type some text in alert popup message
driver.switchTo().alert().sendKeys("text to enter");
15) Press Modifier keys/Functional keys/Tab/Alt/End/Home etc.
a) Key Combination
Eg-: Press Ctrl+A
driver.findElement(By("//body")).sendKeys(Keys.chord(Keys.CONTROL, "t"));
b) Single Key
Eg-: Press F5
driver.findElement(By("//body")).sendKeys(Keys.chord(Keys.F5));
16) Switch to tab or window
String currentWindowHandle= fDriver.getWindowHandle();
for(String windowHandle : fDriver.getWindowHandles())
{
if(!windowHandle.equals(currentWindowHandle))
{
fDriver.switchTo().window(windowHandle);
}
}
17) Switch to frame
a) Switch to the frame defined
WebElement frame1=fDriver.findElement(By.className("demo-frame"));
fDriver.switchTo().frame(frame1);
b) In case of nested frame Switch to the parent frame
fDriver.switchTo().parentFrame();
c) Switch to the page containing the frame
fDriver.switchTo().defaultContent();
18) Action Class
a) Move To Element
Actions actions=new Actions(driver);
actions.moveToElement(elementToPerformOperation);
Action act=actions.build();
act.perform();
b) Left Click
Actions actions=new Actions(driver);
action.moveToElement(elementToPerformOperation).click();
Action act=actions.build();
act.perform();
c) Right Click
Actions actions=new Actions(driver);
actions.contextClick(elementToPerformOperation );
Action act=actions.build();
act.perform();
d) Double Click
Actions actions=new Actions(driver);
actions.doubleClick();
Action act=actions.build(elementToPerformOperation);
act.perform();
e) Type Text
Actions actions=new Actions(driver);
actions.sendKeys(elementToPerformOperation,”text to type” );
Action act=actions.build();
act.perform();
f) Press Key Combination
Actions actions=new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL);
Action act=actions.build();
act.perform();
g) Perform series of Command
Actions actions=new Actions(driver);
WebElement womenPageIndicator=driver.findElement(By.className("navigation_page"));
WebElement searchTextbox=driver.findElement(By.id("search_query_top"));
actions.doubleClick(womenPageIndicator)
.keyDown(Keys.CONTROL).sendKeys("c").keyUp(Keys.CONTROL)
.contextClick(searchTextbox)
.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_D
OWN).sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER);
Action act=actions.build();
act.perform();
h) Drag and Drop
WebElement source=driver.findElement(By.id("draggable"));
WebElement target=driver.findElement(By.id("droppable"));
Actions actions=new Actions(driver);
actions.dragAndDrop(source, target);
Action act=actions.build();
act.perform();
i) Drag and drop to a certain point
Actions actions=new Actions(driver);
actions.dragAndDropBy(driver.findElement(By.id("draggable")),50,50);
Action act=actions.build();
act.perform();
Note: 50, 50 is the offset from the source element
j) Resize(click hold->move mouse->Release)
Actions actions=new Actions(driver);
actions.clickAndHold(elementToHoldToDragForResize).moveByOffset(100, 100).release();
Action act=actions.build();
act.perform();
19) Wait
a) Implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Note: If element is not found in 10 seconds will throw ElementNotVisibleException
Declared at driver level and applicable to all the elements associated with that driver.
b) Explicit Wait
WebDriverWait wait=new WebDriverWait(fDriver,20);
WebElement
droppableLink=wait.until(ExpectedConditions.elementToBeClickable(fDriver.findElement(By.linkText(
"Droppable"))));
c) Fluent Wait