Selenium webdriver 当产品已经添加到购物车中时,其抛出元素是不可单击的异常
Runner.classSelenium webdriver 当产品已经添加到购物车中时,其抛出元素是不可单击的异常,selenium-webdriver,cucumber,cucumber-java,Selenium Webdriver,Cucumber,Cucumber Java,Runner.class Feature: Test Milacron Smoke scenario Scenario: Test login with valid credentials Given open firefox and start application When I click on Login And enter valid "sshankar@genalpha.com" and valid "passw0rd" Then Click o
Feature: Test Milacron Smoke scenario
Scenario: Test login with valid credentials
Given open firefox and start application
When I click on Login
And enter valid "sshankar@genalpha.com" and valid "passw0rd"
Then Click on login and User should be able to login successfully
Scenario: Test shop for cart
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
package runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(features="features",glue={"steps"}, format = {"pretty", "html:target/Destination"})
public class TestRunnr {
}
StepDefinition.class
Feature: Test Milacron Smoke scenario
Scenario: Test login with valid credentials
Given open firefox and start application
When I click on Login
And enter valid "sshankar@genalpha.com" and valid "passw0rd"
Then Click on login and User should be able to login successfully
Scenario: Test shop for cart
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
package runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(features="features",glue={"steps"}, format = {"pretty", "html:target/Destination"})
public class TestRunnr {
}
当任何产品已添加到购物车中时,其未单击购物车和抛出元素为可单击异常,如果购物车为空,则此脚本工作正常,如下所示:
org.openqa.selenium.WebDriverException:元素在点(1193,52)处不可单击。其他元素将收到单击:
命令持续时间或超时:76毫秒
构建信息:版本:“2.53.1”,修订版:“a36b8b1”,时间:“2016-06-30 17:32:46”
系统信息:主机:'WLL16GJ7',ip:'10.1.18.240',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_121'
驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver
功能[{applicationCacheEnabled=true,rotatable=false,handlesAlerts=true,databaseEnabled=true,version=47.0.1,platform=WINDOWS,nativeEvents=false,acceptSslCerts=true,WebStorage Enabled=true,locationContextEnabled=true,browserName=firefox,takesScreenshot=true,javascriptEnabled=true,CSSSelectorEnabled=true}]
会话ID:95fda63b-abc3-4758-825d-223e67522d86
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
位于java.lang.reflect.Constructor.newInstance(Constructor.java:423)
位于org.openqa.selenium.remote.ErrorHandler.CreateTrowable(ErrorHandler.java:206)
位于org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
位于org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
位于org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
在org.openqa.selenium.remote.RemoteWebElement.click上(RemoteWebElement.java:85)
在steps.MilacronSmoke.product应成功添加到购物车中(MilacronSmoke.java:75)
在?处,则应将产品成功添加到购物车中(MyApplication.feature:13)我不确定实际的Java代码,但请尝试引入几毫秒的等待(或等待,如果您希望它在需要时继续),以确保xpath:
//div[包含(@class,'pageLoader')的元素
不再显示在页面上
我有一种感觉,它正在单击add按钮并立即尝试单击cart,但它不能,因为pageLoader元素挡住了它的去路
编辑
我做了一点搜索,找到了,看起来像我刚才说的
这些部分尤其是:
public class MilacronSmoke {
static WebDriver driver;
@Given("^open firefox and start application$")
public void open_firefox_and_start_application() throws Throwable {
driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
driver.get("https://milacronqa.genalphacatalog.com");
}
@When("^I click on Login$")
public void I_click_on_Login() throws Throwable {
driver.findElement(By.xpath("//a[contains(.,'Login')]")).click();
}
@When("^enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$")
public void enter_valid_and_valid(String uname, String pass) throws Throwable {
driver.findElement(By.id("Username")).sendKeys(uname);
driver.findElement(By.id("Password")).sendKeys(pass);
}
@Then("^Click on login and User should be able to login successfully$")
public void Click_on_login_and_User_should_be_able_to_login_successfully() throws Throwable {
driver.findElement(By.id("loginUser")).click();
}
@Given("^Click on shop for carts$")
public void Click_on_shop_for_carts() throws Throwable {
driver.findElement(By.xpath("//span[text()='Shop for Parts']")).click();
}
@Given("^select plates$")
public void select_plates() throws Throwable {
driver.findElement(By.xpath("//a[contains(.,'Plates ')]")).click();
}
@When("^Click on Add to cart$")
public void Click_on_Add_to_cart() throws Throwable {
driver.findElement(By.xpath(".//*[@id='product-catalog-hldr']/div[1]/div[4]/button[1]")).click();
}
@Then("^product should be added in the cart successfully$")
public void product_should_be_added_in_the_cart_successfully() throws Throwable {
WebElement element = driver.findElement(By.xpath("//a[contains(.,'Cart1')]"));
element.click();
WebElement element1=driver.findElement(By.xpath("//a[contains(.,'Item # 10010773')]"));
String str=element1.getText();
System.out.println(str);
Assert.assertEquals("Item # 10010773", str);
System.out.println("Test passed successfully");
}
}
及
当然,您的代码更像这样:
WebDriverWait wait = new WebDriverWait(webDriver, 1);
wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
请记住在步骤定义文件中包含include语句为AUT提供HTML代码段。