I have issue while automating Odoo application - java

i am automating Odoo pos application. but while adding product to the cart, i got error like "Element is not clickable at point (659,166)". i have already created 1 item and trying to add that in cart but element is not found. need help.
package odoo1;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class odoo {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Chrome\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
// for Log in functionality
driver.get("https://www.odoo.com/trial?selected_app=point_of_sale");
driver.findElement(By.id("username")).sendKeys("mark");
driver.findElement(By.id("email")).sendKeys("mark#gmail.com");
driver.findElement(By.id("company-name")).sendKeys("odooo");
driver.findElement(By.id("phone")).sendKeys("561234897");
driver.findElement(By.id("country-id")).sendKeys("India");
driver.findElement(By.name("lang")).sendKeys("English");
Select sell=new Select(driver.findElement(By.name("company_size")));
sell.selectByIndex(2);;
Select sell1=new Select(driver.findElement(By.id("plan")));
sell1.selectByIndex(2);
driver.findElement(By.xpath(".//*[#id='wrapwrap']/main/div/div/div[2]/div[2]/div/form/input[8]")).click();
// for creating product
driver.findElement(By.xpath("html/body/div[3]/div[3]/div[1]/a[2]/div[2]")).click();
driver.findElement(By.xpath("html/body/nav/div/ul[1]/li[2]/a")).click();
driver.findElement(By.xpath("html/body/nav/div/ul[1]/li[2]/ul/li[3]/a/span")).click();
driver.findElement(By.xpath("html/body/div[3]/div[2]/div[1]/div/button")).click();
driver.findElement(By.xpath(".//*[#id='o_field_input_4']")).sendKeys("iphone");
driver.findElement(By.xpath(".//*[#id='o_field_input_4']")).click();
driver.findElement(By.xpath(".//*[#id='o_field_input_13']")).sendKeys("abcd");
driver.findElement(By.xpath(".//*[#id='o_field_input_14']")).sendKeys("123456");
driver.findElement(By.xpath(".//*[#id='o_field_input_15']"));
driver.findElement(By.xpath(".//*[#id='o_field_input_16']")).clear();
driver.findElement(By.xpath(".//*[#id='o_field_input_16']")).sendKeys("25000");
driver.findElement(By.xpath(".//*[#id='o_field_input_20']")).clear();
driver.findElement(By.xpath(".//*[#id='o_field_input_20']")).sendKeys("25000");
Thread.sleep(1000);
driver.findElement(By.xpath("html/body/div[3]/div[2]/div[1]/div/div[2]/button[1]")).click();
Thread.sleep(900);
driver.findElement(By.xpath("html/body/nav/div/ul[1]/li[1]/a/span")).click();
driver.findElement(By.xpath("html/body/div[4]/div/div/div[1]/div[2]/div/div[1]/button")).click();
Thread.sleep(500);
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[2]/table/tbody/tr[2]/td/div/div/div/div/span[2]/div[1]")).click();
Thread.sleep(700);
driver.findElement(By.xpath("//button")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div[2]/div[1]/div/div/div/div[2]/div[2]/table/tbody/tr[2]/td/div/div/div/div/span[2]/div[1]/img")).click();
}
}

By looking at the exception, it looks like the right path is not selected.
I have just checked the website which you are trying to automate.
Steps I have followed:
Click on Open Cart tab.
Select Shipping option.
Click on Add to Cart for the product which you want to add in your path.
Xpath Used for Add To Cart button:
//h3[normalize-space()="Opencart Marketplace"]/../div[3]//button
I have selected the product "Opencart Marketplace". You can select any product you want. Just replace Opencart Marketplace with the product which you want to select.
Code:
System.setProperty("webdriver.gecko.driver", "src/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://store.webkul.com/OpenCart-Modules.html");
Thread.sleep(2);
driver.findElement(By.xpath("//h3[normalize-space()='Opencart Marketplace']/../div[3]//button")).click();
driver.findElement(By.xpath("//div[#class='product_cart_container']/button")).click();

Related

How to validate html5 constraint validation message using Selenium-Webdriver and Java [duplicate]

This question already has answers here:
How to handle HTML constraint validation pop-up using Selenium?
(3 answers)
Closed 3 months ago.
How do I validate the following message? The required class has the floating message.:
try the following, but I get the error "no such alert"
package firsttestngpackage;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
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.testng.Assert;
import org.testng.annotations.Test;
public class LoginBambu {
public String baseUrl = "http://132.148.19.159:8086/panel/#/login";
String driverPath = "H:\\chromedriver.exe";
public WebDriver driver;
#Test
public void IniciarSesion() {
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseUrl);
WebElement login = driver.findElement(By.cssSelector("#page-top > div.margen-panel-60.ng-scope > div > div.row.container-fluid.ng-scope > div:nth-child(1) > div > form > button"));
login.click();
String mensaje=driver.switchTo().alert().getText();
System.out.println(mensaje);
}
}
The HTML5 Constraint validation message is the outcome of Constraint API's element.setCustomValidity() method.
Note: HTML5 Constraint validation doesn't remove the need for validation on the server side. Even though far fewer invalid form requests are to be expected, invalid ones can still be sent by non-compliant browsers (for instance, browsers without HTML5 and without JavaScript) or by bad guys trying to trick your web application. Therefore, like with HTML4, you need to also validate input constraints on the server side, in a way that is consistent with what is done on the client side.
Solution
To retrieve the text which results out from the element.setCustomValidity() method, you can use the following solution:
Code Block:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class validationmessage {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("http://132.148.19.159:8086/panel/#/login");
WebElement username = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control.ng-pristine.ng-invalid.ng-invalid-required.ng-touched[placeholder='Usuario']")));
System.out.println(username.getAttribute("validationMessage"));
}
}
Console Output:
Please fill out this field.

Android app closes after .click() command

I'm trying to automate a app to do everything that you would have to do by hand. My main goal right now is to get it to click a button after logging into the app.
This is the very last line of code in my IDE
driver.findElement(By.id("com.offerup:id/main_text")).click();
After this line of code executes, OfferUp, the app that I'm testing on, closes. There are no failures in console but, I don't want it to close after that line of code executes.
When I log into the app without running my code, the app stays open but, when I run my code, it closes after driver.findElement(By.id("com.offerup:id/main_text")).click(); is executed.
Why this is happening?
Here is my full code -
package OpenOfferUpTest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.server.handler.FindElement;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class OpenOfferUp {
AndroidDriver driver;
#Test
public void OpensOfferUp() throws MalformedURLException
{
File OfferUp = new File("C:\\Users\\boung\\Desktop\\OfferUp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Virtual Device");
cap.setCapability("platformName", "android");
cap.setCapability("null", "OfferUp");
cap.setCapability("appPackage", "com.offerup");
cap.setCapability("appActivity", "com.offerup.android.login.splash.LoginSplashActivity");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);
}
#Test
public void SimpleTest() throws InterruptedException {
driver.findElement(By.id("com.offerup:id/email_button")).click();
By path = By.xpath("//*[#text='Enter your email address']");
driver.findElement(path).sendKeys("sourgta#gmail.com");
driver.findElement(By.id("com.offerup:id/next_button")).click();
By path1 = By.xpath("//*[#text='']");
driver.findElement(path1).sendKeys("12manytimes");
driver.findElement(By.id("com.offerup:id/main_text")).click();
}
}

"cannot instantiate the type select" while selecting an item from drop down

package Saradhi;
import java.util.concurrent.TimeUnit;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginAndNavigate {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "E:ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://opensource.demo.orangehrmlive.com/");
WebElement frmtime = driver.findElement(By.id("workShift_workHours_from"));
Select se = new Select(frmtime); // error line
I'm getting an error message in the above line.
I have tried importing related packages but still didn't work.
You are importing a wrong package. Try
import org.openqa.selenium.support.ui.Select;
instead of
import org.apache.bcel.generic.Select;
Use this import:
import org.openqa.selenium.support.ui.Select;
And remove this one:
import org.apache.bcel.generic.Select;

Error :Cannot instantiate the type Select in selenium webdriver

I am testing a website with selenium webdriver.
I have imported all the jar files also, but still could not use Select Class in eclipse. It gives me an error: Select class cannot be instantiated.
I have also imported org.openqa.selenium.support.ui.Select
Following is my source code
import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Dropdown {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("http://www.makemytrip.com");
WebElementaddress=driver.findElement(By.xpath(".//[#id='to_typeahead1']"));
Select sc = new Select (address); // ERROR LINE
sc.selectByIndex(5);
}
}
You may try the below. Lets break it down into parts.
Select sc = new Select(driver.findElement(By.xpath("your Xpath match case")));
**//this will get the dropdown into sc object**
List<WebElement> we = sc.getOptions(); **//to get the options values into list**
System.out.println(we.size()); **//to print the size in console, this and
previous lines for debug/cross checking**
sc.selectByIndex(5); **//this will select the 5th index and 6th value(indexing starts from 0)**
Cheers!
Import org.openqa.selenium.support.ui.Select; package in your project, instead of org.apache.bcel.generic.Select;
Error will go off.
I see that the Xpath you have provided is not correct.
It should be .//*[#id='to_typeahead1']
Moreover, this element is not a select box. Its an input box.
What you can probably try is to click on the element and then try to click on the option you want to select.
I have used the org.openqa.selenium.support.ui.Select package and it worked fine.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
public class NewClassTest {
WebDriver driver = new FirefoxDriver();
#Test
public void selectOption() {
driver.get("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select");
WebElement address = driver.findElement(By.tagName("select"));
Select ab = new Select(address);
}
}

How to import select class in webdriver?

I tried importing select class in my program using selenium webdriver,
but I am not able to import the predefined package.
Can anyone please guide me on this?
package com.siri.dev;
import org.apache.bcel.generic.Select;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyntraTests {
private WebDriver driver;
#Before
public void setup() {
intializedriver("firefox");
}
#Test
public void get() {
driver.get("http://www.myntra.com");
driver=waitForPageLoaded(driver);
driver.manage().window().maximize();
System.out.println("Page opened successfully");
WebElement element = driver.findElement(By.className("tab"));
org.openqa.selenium.support.ui.Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
}
private void intializedriver(String browser) {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().window().maximize();
}
import org.openqa.selenium.support.ui.Select;
Use
Select selectElement = new Select(driver.findElement(By.cssSelector("")));
The reason you are having this
org.openqa.selenium.support.ui.Select elem = new Select(element);
is cause you have imported a wrong class imported already
import org.apache.bcel.generic.Select;
remove that import by deleting it and then
import org.openqa.selenium.support.ui.Select
If you are using Eclipse you can always remove unused imports by ctrl+shift+o.
Select is a class of package org.openqa.selenium.support.ui
So you are supposed to do a import statement as follows:
import org.openqa.selenium.support.ui.Select;
and then you can do your task as:
Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
U have imported a wrong package : import org.apache.bcel.generic.Select;
If you use Maven, you will want to know that packages under org.openqa.selenium.support are in artifact selenium-support. That does not get pulled in along with selenium-api or any of the selenium-*-driver artifacts. You can refer to the Selenium Maven information.

Categories

Resources