I develop automated test with iPhone, Selenium and Appium. I need to perform touch action on current screen position.
Can You help me? Do You have any sample code? I checked this solution but it doesn't work
new TouchActions(wd).down(0, 0).move(150, 0).perform();
try to use TouchAction class this way:
TouchAction action = new TouchAction();
action.longPress(webElement).moveTo(webElement).release().perform();
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(startx+" "+starty);
System.out.println("Entering swipe");
System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();
Related
I'd like to have my selenium webdriver running in background while doing something else but each time I switch from window where test is executing it fails.
It seems that WebDriver doesn't remember handler for window where started tests - is it ok behaviour ? What is solution then ?
For running Selenium WebDriver in background you need to use headless webdriver for that you can use following code
public static void main(String[] args) {
// Declaring and initialising the HtmlUnitWebDriver
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
// open google.com webpage
unitDriver.get("http://google.com");
System.out.println("Title of the page is -> " + unitDriver.getTitle());
// find the search edit box on the google page
WebElement searchBox = unitDriver.findElement(By.name("q"));
// type in Selenium
searchBox.sendKeys("Selenium");
// find the search button
WebElement button = unitDriver.findElement(By.name("gbqfba"));
// Click the button
button.click();
System.out.println("Title of the page is -> " + unitDriver.getTitle());
}
Below is the code
WebDriver dr= new ChromeDriver();
dr.get("http://obsessory.com/");
dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[1]/a")).click();
dr.findElement(By.id("email")).sendKeys("username#gmail.com");
dr.findElement(By.name("LoginForm[password]")).sendKeys("password");
dr.findElement(By.xpath(".//[#id='signIn']/div[2]/div[3]/div[3]/input")).click();
Actions action = new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).moveToElement(dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"))).click().build().perform();
I wanted to click on 'my accounts' or any of those other links. Kindle tell me how to do that
#kavya
Please try this code. I think you are not able to type password in password textbox.
For password:
dr.findElement(By.xpath("(//input[#id='email'])[2]")).sendKeys("obsessory");
For Menu:
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a"));
WebElement ve = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"));
Actions act = new Actions(dr);
act.moveToElement(we).click(ve).perform();
Hope this will work
Try with
Actions action= new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).perform();
By locator = By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a");
dr.click(locator);
I have been trying to use PhantomJSWebDriver framework for automating an application using Headless browser. The main issue is as we can successfully switch between windows in firefox or IE windows, here I am not able to switch between windows based on handles. Please help me.
Below is the code I have tried so far.
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
driver = new PhantomJSDriver();
driver.get(application url);
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
WebElement txtUsername = driver.findElement(By.id("it_C_C5"));
txtUsername.sendKeys("sreenis");
WebElement txtPassword = driver.findElement(By.id("it_C_C7"));
txtPassword.sendKeys("sreeni");
WebElement btnLogin = driver.findElement(By.id("ic_C_C8"));
btnLogin.click();
Thread.sleep(10000);
String winTitle = "Role profile selection";
boolean bool = switchWindow(winTitle);
if (bool){
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
else {
System.out.println("Switch to window '" + winTitle + "' failed!");
driver.quit();
}
public static boolean switchWindow(String windowtitle){
String mainWindowsHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
System.out.println(handles.size());
for(String winHandle : handles){
driver.switchTo().window(winHandle);
System.out.println(driver.getTitle());
if(driver.getTitle().toLowerCase().equals(windowtitle)){
return true;
}
}
driver.switchTo().window(mainWindowsHandle);
return false;
}
When I tried to print the window titles in collection, it is only printing the parent window and not the other windows. I am not able to guess what is happening since nothing can be seen and it is headless testing. Please suggest me is there any other way so that I can test the app with many browser windows.
Actions act = new Actions(d);
act.contextClick(elements).sendKeys("W").perform();
Set<String> win = d.getWindowHandles();
Iterator <String> itrwin = win.iterator();
String parent = itrwin.next();
String child = itrwin.next();
d.switchTo().window(child);
identify an web element first using findElement() and store it in element.
Long time lurker; first time poster. I'm fairly new to the Selenium API and WebDriver, and I'm having a small problem.
In short, I am attempting to leverage the Firefox tab feature using Selenium's FirefoxDriver, but my driver instance object is not returning the correct URL using its getCurrentUrl() method when switching between tabs. Here is a brief example of what I am trying to accomplish:
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
// display starting tab URL
System.out.println(driver.getCurrentUrl()); // expected output: google.com
WebElement body = driver.findElement(By.cssSelector("body"));
// open new tab
if(System.getProperty("os.name").contains("Mac")) {
body.sendKeys(Keys.COMMAND + "t");
}
else {
body.sendKeys(Keys.CONTROL + "t");
}
//navigate in new tab
driver.get("http://www.yahoo.com");
// display new tab URL
System.out.println(driver.getCurrentUrl()); // expected output: yahoo.com
//navigate back to previous tab
body = driver.findElement(By.cssSelector("body"));
body.sendKeys(Keys.CONTROL +""+Keys.SHIFT +""+ Keys.TAB);
// display starting tab URL
System.out.println(driver.getCurrentUrl()); // expected output: google.com
driver.close();
However, on execution the output reads:
google
yahoo
yahoo
My intuition suggests that the driver's frame/tab view is not being updated quickly enough, or at all, but I am not sure how to determine this. Any help would be greatly appreciated.
Thanks!
I found a solution/workaround to correct the driver's current view. After the driver switches to a different tab, a call to switchTo().defaultContent() must be made.
The working code is as follows:
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
// display starting tab URL
System.out.println(driver.getCurrentUrl()); // expected output: google.com
WebElement body = driver.findElement(By.cssSelector("body"));
// open new tab
if(System.getProperty("os.name").contains("Mac")) {
body.sendKeys(Keys.COMMAND + "t");
}
else {
body.sendKeys(Keys.CONTROL + "t");
}
//navigate in new tab
driver.get("http://www.yahoo.com");
// display new tab URL
System.out.println(driver.getCurrentUrl()); // expected output: yahoo.com
//navigate back to previous tab
body = driver.findElement(By.cssSelector("body"));
body.sendKeys(Keys.CONTROL +""+Keys.SHIFT +""+ Keys.TAB);
// refresh driver view
driver.switchTo().defaultContent();
// display starting tab URL
System.out.println(driver.getCurrentUrl()); // expected output: google.com
driver.close();
The new resulting output now matches what is expected:
google
yahoo
google
if i debug same code then its working fine but when run this code then Mouse Action is not not working.
code are following -
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("url");
driver.findElementByXPath("xpath").click();
driver.findElementByXPath("xpath").sendKeys("gg");
driver.findElementByXPath("xpath").click();
boolean saleIdVisible =driver.findElementByXPath("path").isEnabled();
if(saleIdVisible==true){
Actions mouseaction=new Actions(driver);
WebElement payment_lk1 = driver.findElement(By.xpath("path"));
mouseaction.moveToElement(payment_lk1).build().perform();
mouseaction.click(payment_lk1).build().perform();
System.out.println("order id is not found ");
}else{
System.out.println("order id is found ");
}
driver.findElementByXPath("path").click();
driver.findElementByXPath("path").click();
driver.findElementByXPath("path").clear();
driver.findElementByXPath("path").sendKeys("95032");
driver.findElementByXPath("path").click();
}
You don't need to do 2 steps for that kind of action.
mouseaction.click(payment_lk1).build().perform();
instead of
mouseaction.moveToElement(payment_lk1).build().perform();
mouseaction.click(payment_lk1).build().perform();
Can you explain more about your : payment_lk1. Is this a link ? Button ? ...
PS : Take care there
boolean saleIdVisible =driver.findElementByXPath("path").isEnabled();
because a button can be enabled but not visible. ;)