Selenium Answers
Selenium Answers
Selenium Answers
System.out.println(title);
System.out.println(title);
System.out.println(title);
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
email.sendKeys("vinoth");
WebElement pass = driver.findElement(By.xpath("//input[@id='pass']"));
pass.sendKeys("12345678");
login.click();
//Get Attribute
String attribute = webelementRef.getAttribute("value");
System.out.println(attribute);
//Get Text
String text = webelementRef.getText();
System.out.println(text);
a.moveToElement(ref).perform();
a.dragAndDrop(source, target).perform();
a.contextClick(ref).perform();
9. write code for double click?
Actions a = new Actions(driver);
a.doubleClick(ref).perform();
a.keyDown(Keys.SHIFT).perform();
ref.sendKeys("vinoth");
a.keyUp(Keys.SHIFT).perform();
O/P : VINOTH
(C+A)
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_A);
r.keyRelease(KeyEvent.VK_A);
r.keyRelease(KeyEvent.VK_CONTROL);
(C+C)
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_C);
r.keyRelease(KeyEvent.VK_C);
r.keyRelease(KeyEvent.VK_CONTROL);
(C+V)
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
12 Write a code for simple alert, confirm alert and prompt alert
Alert alert = driver.switchTo().alert();
simple alert :
alert.accept();
confirm alert :
alert.accept();
alert.dismiss();
prompt alert :
alert.accept();
alert.dismiss();
alert.sendKeys(value);
FileUtils.copyFile(screenshotAs,image);
15.Write a code to take Screenshot for Element
TakesScreenshot ts=(TakesScreenshot) driver;
FileUtils.copyFile(screenshotAs,image);
js.executeScript("arguments[0].setAttribute('value','java’)", webelementRef);
js.executeScript("arguments[0].click()", webelementRef);
js.executeScript("arguments[0].ScrollIntoView(true)", webelementRef );
js.executeScript("arguments[0].ScrollIntoView(false)", webelementRef);
s.selectByValue(value);
s.selectByIndex(i);
}
21. Drop Down-get the all selected values
Select s=new Select(webelementRef);
System.out.println(aso);
s.deselectByIndex(i);
s.deselectAll();
24. Drop Down- Write a code to get the all options count
Select s=new Select(webelementRef);
System.out.println(count);
System.out.println(count);
driver.switchTo().frame(1);
driver.switchTo().frame(2);
27 Write a code to switch into frame(possible ways)
By Index
driver.switchTo().frame(index);
By Name or Id
driver.switchTo().frame(“id or name”);
By Web Element
driver.switchTo().frame(WebElement);
System.out.println(count);
Iterator<String> il = child.iterator();
while(il.hasNext()) {
String nextwindow = il.next();
if (!nextwindow.equals(mainwindow)) {
driver.switchTo().window(nextwindow);
TakesScreenshot
JavascriptExecutor
WebElement
Alert
Navigation
SearchContext
OutputType
NoSuchFrameException
NoSuchElementException
NoAlertPresentException
InvalidSelectorException
TimeoutException
ElementNotVisibleException
ElementNotSelectableException
NoSuchSessionException
StaleElementReferenceException
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
System.out.println(count);
System.out.println(count);
System.out.println(count);
driver.navigate().forward();
driver.navigate().refresh();
driver.navigate().to(“url”);