Java 我在自动化Odoo应用程序时遇到问题
我正在自动化Odoo pos应用程序。但在将产品添加到购物车时,我遇到了类似“元素在点(659166)处不可单击”的错误。我已经创建了1个项目,并试图将其添加到购物车中,但找不到元素。我需要帮助Java 我在自动化Odoo应用程序时遇到问题,java,selenium,Java,Selenium,我正在自动化Odoo pos应用程序。但在将产品添加到购物车时,我遇到了类似“元素在点(659166)处不可单击”的错误。我已经创建了1个项目,并试图将其添加到购物车中,但找不到元素。我需要帮助 package odoo1; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Alert; import org.openqa.selenium.By; imp
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();
}
}
通过查看异常,似乎未选择正确的路径。 我刚刚检查了你正在尝试自动化的网站 我遵循的步骤:
findElement(By.xpath(“//div[@class='product\u cart\u container']/button”)。单击() 你应该与error stacktraceShare一起分享你的代码和该元素的html。如果你分享你尝试过的内容会更好。我已经检查了Odoo的网站,其中购物车无法点击,而当你悬停鼠标时,它会列出添加到购物车中的内容。我想你需要使用action。有关更多详细信息,请参阅此链接