简体   繁体   English

如何启用按钮在Selenium WebDriver中进行验证?

[英]How to enable button do verify in Selenium WebDriver?

I have one button section product, but it disables when hover mouse on section product then the button is enabled. 我有一个按钮部分产品,但是将鼠标悬停在部分产品上时会禁用该按钮。 I don't know write script do enable a button when Selenium WebDriver finds it. 我不知道Selenium WebDriver找到写脚本后是否会启用按钮。

@Test(priority = 4)
public void TestSelectedItem() {

    driver.findElement(By.xpath("/html/body/app-root/ng-component/div/product-list/div/div/div/div/div[2]/div/div[3]/div/div[1]/a")).click();
    Select drpItem = new Select(driver.findElement(By.id("pa_colors")));
    drpItem.selectByIndex(2);
    driver.findElement(By.className("add_to_cart_button")).click();

}

Please help me. 请帮我。

I will give you code in Python which do hover action on the element: 我将在Python中为您提供对元素进行悬停操作的代码:

hover_company = driver.find_element_by_xpath("your XPath")
driver.execute_script("arguments[0].scrollIntoView(true);", hover_company)
hover = ActionChains(driver).move_to_element(hover_company)
hover.perform()

First two lines scroll to your element, last two lines -- do hover action on the element. 前两行滚动到您的元素,后两行-对元素进行悬停操作。 After this action -- you can click on the button. 完成此操作后-您可以单击按钮。 Try on. 试一下。

Code in Java: Java代码:

hover_company = driver.findElement(By.xpath("your XPath"));
driver.executeScript("arguments[0].scrollIntoView(true);", hover_company);
Actions hover = new Actions(driver);
hover.moveToElement(hover_company).perform();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM