我正在自动化Odoo pos应用程序。但是在将产品添加到购物车时,我得到了错误,例如"元素在点(659,166)和#34;处不可点击。我已经创建了1个项目并尝试在购物车中添加该项目但未找到元素。需要帮助。
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();
}
}
答案 0 :(得分:0)
通过查看异常,看起来未选择正确的路径。 我刚刚查看了您要尝试自动化的网站。
我遵循的步骤:
Xpath用于添加到购物车按钮:
// h3 [normalize-space()=" Opencart Marketplace"] /../ div [3] //按钮
我选择了产品" Opencart Marketplace"。您可以选择所需的任何产品。只需将 Opencart Marketplace 替换为您要选择的产品。
<强>代码:强>
System.setProperty(&#34; webdriver.gecko.driver&#34;,&#34; src / geckodriver&#34;);
WebDriver driver = new FirefoxDriver();
driver.get(&#34; https://store.webkul.com/OpenCart-Modules.html&#34);
的Thread.sleep(2);
driver.findElement(By.xpath(&#34; // h3 [normalize-space()=&#39; Opencart Marketplace&#39;] /../ div [3] // button&#34;) )。单击();
driver.findElement(By.xpath(&#34; // DIV [@class =&#39; product_cart_container&#39;] /按钮&#34))点击();