0

如果我调试相同的代码,那么它可以正常工作,但是当运行此代码时,鼠标操作不起作用。代码如下 -

public static void main(String[] args) {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("url");
        driver.findElementByXPath("xpath").click();
        driver.findElementByXPath("xpath").sendKeys("gg");
        driver.findElementByXPath("xpath").click();
        boolean saleIdVisible =driver.findElementByXPath("path").isEnabled();
        if(saleIdVisible==true){
            Actions mouseaction=new Actions(driver);
            WebElement payment_lk1 = driver.findElement(By.xpath("path"));
            mouseaction.moveToElement(payment_lk1).build().perform();
            mouseaction.click(payment_lk1).build().perform();
            System.out.println("order id is not found ");
        }else{
            System.out.println("order id is  found ");
        }
            driver.findElementByXPath("path").click();
            driver.findElementByXPath("path").click();
            driver.findElementByXPath("path").clear();
            driver.findElementByXPath("path").sendKeys("95032");
            driver.findElementByXPath("path").click();
        }
4

1 回答 1

0

您无需为此类操作执行 2 个步骤。

mouseaction.click(payment_lk1).build().perform();

代替

mouseaction.moveToElement(payment_lk1).build().perform();
mouseaction.click(payment_lk1).build().perform();

你能解释更多关于你的:payment_lk1。这是一个链接吗?按钮 ?...

PS:注意那里

boolean saleIdVisible =driver.findElementByXPath("path").isEnabled();

因为按钮可以启用但不可见。;)

于 2013-06-26T14:19:44.947 回答