Im using automation with Selenium and JAVA (Eclipse) and im trying to aplying an automation test but i cant select the "prompt box" for inssert the text into the fields...
my code dont send "text" to my fields
this is a windows like a pop up where i need insert text and clic on "Aceptar", but actually my code doesn't work, just open the navigator and clic in the button and the test finished..
this is my code:
package Driver;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import java.util.concurrent.TimeUnit;
import org.testng.Assert;
import org.testng.annotations.*;
import com.thoughtworks.selenium.webdriven.commands.SelectWindow;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.server.handler.GetAllWindowHandles;
import org.openqa.selenium.support.ui.Select;
import java.io.*;
public class Parametria {
public static void main (String[] args) throws Exception{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("MY WWWW URL");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("form:table:buttonAdd")).click();
driver.switchTo().frame("form:panelAdd_content");
driver.findElement(By.id("form:headerType")).clear();
driver.findElement(By.xpath("//*[#id='form:headerType']']")).sendKeys("Parametro_1");
// driver.findElement(By.name("form:headerType']']")).sendKeys("Parametro_1");
driver.findElement(By.id("form:nameType")).clear();
driver.findElement(By.xpath("//*[#id='form:nameType']")).sendKeys("Parametro_2");
driver.findElement(By.xpath("//*[#id='form:value1']/span")).click();
driver.findElement(By.xpath("//*[#id='form:j_idt72']")).click();
driver.navigate().back();
driver.quit();
}
}
Related
I can't find a button using id or xpath using pagefactory on expedia.com website. It says no such element: Unable to locate element "tab-flight-tab-flp".
I tried using id and xpath. It gives same error. I wonder this is happening?
It says no such element: Unable to locate element "tab-flight-tab-flp".
I tried using id and xpath. It gives same error. I wonder this is happening?
It says no such element: Unable to locate element "tab-flight-tab-flp".
I tried using id and xpath. It gives same error. I wonder this is happening?
package UsefulPackages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class SearchPageFactory {
WebDriver adriver;
#FindBy(id="tab-flight-tab-flp")
WebElement flightTab;
//constructor
public SearchPageFactory(WebDriver driver) {
this.adriver = driver;
PageFactory.initElements(driver, this);
}
public void clickFlightTab(){
flightTab.click();
}
}
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import UsefulPackages.SearchPageFactory;
public class FrameworkTestCase {
WebDriver achromeDriver;
String abaseUrl;
SearchPageFactory apagefactory;
#Before
public void setUp() throws Exception {
abaseUrl = "http://www.expedia.com";
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\ChromeDirver\\chromedriver.exe");
achromeDriver = new ChromeDriver();
apagefactory = new SearchPageFactory(achromeDriver);
chromeDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
achromeDriver.manage().window().maximize();
System.out.println("setup completed");
}
#Test
public void test() {
achromeDriver.get(abaseUrl);
WebDriverWait awaittime = new WebDriverWait(achromeDriver, 10);
System.out.println("page factory created");
apagefactory.clickFlightTab();
}
}
Is you want get Flights button ?
It will achieve with :
Find by id :
#FindBy(id="tab-flight-tab-hp")
Find by xpath :
#FindBy(xpath="//button[#id='tab-flight-tab-hp']")
I am trying double click and copy paste scenarios on yahoo.com but it is not working. Want to copy the text "Sign in" and paste in username
{ package com.yahoo.com;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;`
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class YahooTests {
WebDriver driver;
#Test
public void test01_InvokeBrowserApp(){
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
{ Actions act = new Actions(driver);
WebElement copy = driver.findElement(By.xpath(".//*[#id='mbr-login-greeting']"));
act.moveToElement(copy).doubleClick().sendKeys(Keys.CONTROL+"C").build().perform();
act.doubleClick(paste).sendKeys(Keys.CONTROL+"V");
WebElement paste = driver.findElement(By.xpath(".//*[#id='login-username']"));
}
Try This hope problem will be solved
act.moveToElement(By.xpath(".//*[#id='mbr-login-greeting']")).doubleClick().build().perform();
// catch here is double click on the text will by default select the text
// now apply copy command
driver.findElement(By.xpath(".//*[#id='mbr-login-greeting']")).sendKeys(Keys.chord(Keys.CONTROL,"c"));
// now apply the command to paste
driver.findElement (By.xpath(".//*[#id='login-username']").sendKeys(Keys.chord(Keys.CONTROL, "v"));
I am trying to self learn Selenium, but I am not able to figure out how to close or select from a dropdown which opens once I enter destination into input box.
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Dropdown {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:/Users/Karthik/Desktop/Education/Selenium Short/geckodriver-v0.11.1-win64/geckodriver.exe");
WebDriver D= new FirefoxDriver ();
D.get("https://www.kayak.com/flights");
System.out.println(D.getCurrentUrl());
D.findElement(By.xpath(".//span[text()='One-way']")).click();
D.findElement(By.xpath("//*[#name='origin']")).clear();
D.findElement(By.xpath("//*[#name='origin']")).sendKeys("TPA");
D.findElement(By.xpath("//*[#name='destination']")).sendKeys("DEL");
D.findElement(By.xpath(".//span[class()='airportCode']")).click();
WebElement abc=D.findElement(By.xpath(".//*[#class='ap selected']"));
Alert Work=D.switchTo().alert();
Work.accept();
abc.click();
D.findElement(By.xpath("//*[.//span[text()='Depart']")).sendKeys("02/21/2017");
}
}
try using :
D.findElement(By.xpath("//*[#name='destination']")).sendKeys(Keys.ENTER);
after :
D.findElement(By.xpath("//*[#name='destination']")).sendKeys("DEL");
How to test or verify check box is selected or not selected by using selenium webdriver java
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class Qemr { public static void main(String[]args){
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
chkPersist=click();
for(int i=0;i<2;i++){
System.out.println("chkPersist.isChecked()");
}
}
}
yes there are methods available which you can use for ny kind of controls, for eg. for check box you can use isSelected() method which returns boolean value i.e. 0/1
for your scenario
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class Qemr {
public static void main(String[]args)
{
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
//chkPersist.click();
if(chkPersist.isSelected())
{
System.out.println("Check box is Selected..");
}
}
}
driver.findElement("").isSelected() option is there to check whether Checkbox is selected. you can find solution in your updated code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class StackOverFlow1
{
public static void main(String[]args)
{
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
String baseUrl="http://192.168.1.3:9091";
driver.get(baseUrl);
boolean chkPersist=driver.findElement(By.name("remember")).isSelected();
if(chkPersist)
{
System.out.println("chkPersist is in selected state");
}
}
}
}
Question : How to test or verify check box is selected or not selected by using selenium webdriver java.
Answer : Yes we can verify webelement is selected or not using isSelected() method
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import java.util.concurrent.*;
public class Qemr {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
// Verify chkPersist element is Selected or Not ?
if (chkPersist.isSelected()) {
// if chkPersist element is selected then we print message
System.out.println("chkPersist element is already selected");
} else {
// if chkPersist element is not selected then we select / click on chkPersist element
chkPersist.click();
}
}
}
stacktrace screenshot I am trying to run different tests that I have written, through Appium on an Android device, but I am getting the following errors:
unable to load class 'org.eclipse.ui.internal.ide.application.addons.ModelCleanupAddon' from bundle '731'
or
unable to load class 'org.eclipse.ui.internal.ide.application.addons.ModelCleanupAddon' from bundle '561'
My code is:
import org.openqa.selenium.By;
//import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.DesiredCapabilities;
//import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
//import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;
import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
//import java.util.concurrent.TimeUnit;
//import org.junit.Test;
public class CustomerLogin {
AppiumDriver driver;
takeScreenshot SC;
#BeforeClass
public void setUp() throws MalformedURLException{
File app = new File(System.getProperty("user.dir")+ "\\apks\\DropCarOwner-STAGE-v2.1.0-rc.1.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("DeviceName","306SH");
capabilities.setCapability("PlatformValue", "4.4.2");
capabilities.setCapability("PlatformName", "Android");
capabilities.setCapability("app",app.getAbsolutePath());
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}*/
#Test
public void Login() throws Exception{
WebElement email= driver.findElement(By.id("com.dropcar.owner:id/editTextEmailAddress"));//com.dropcar.owner:id/editTextEmailAddress
email.sendKeys("a","w","a","i","s","d","u","r","r","a","n","i","8","7","#","g","m","a","i","l",".","c","o","m");
WebElement password= driver.findElement(By.id("com.dropcar.owner:id/editTextPassword")); //com.dropcar.owner:id/editTextPassword
password.sendKeys("c","h","e","c","k","i","n","g","1","2","3");
WebElement check= driver.findElement(By.name("Remember me")); //com.dropcar.owner:id/checkBoxRememberMe
driver.tap(0, check,0);
//check.click();
WebElement signIn=driver.findElement(By.name("SIGN IN"));
driver.tap(1,signIn,1);
//signIn.click();
SC.Screenshot(driver);
}
#AfterTest
public void end(){
driver.quit();
}
}
I am using Eclipse 4.4.1. How can I resolve this error?
Make sure before running the script appium-doctor command is working successfully. If you will attach the appium log then it will be more easy to tell you the actual solution of your problem.