Selenium / Firefox: Command “.click()” doesn't work with a found element

后端 未结 6 2232
陌清茗
陌清茗 2020-12-14 08:17

I tried to find a solution to this thing and I spent a lot of time, but it is almost imposible to me to do that.

The matter: I am using Selenium with Java in Firefox

相关标签:
6条回答
  • 2020-12-14 08:58
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.click(element);
    Action action = actions.build();
    action.perform();
    

    This worked for me.

    0 讨论(0)
  • 2020-12-14 09:09

    I have the same problem in Firefox. The trick is to click the text inside of not the button itself.

    0 讨论(0)
  • 2020-12-14 09:09

    You can try to use the Actions class from org.openqa.selenium.interactions:

    WebElement element = driver.findElement(By.id("size-btn"));
    Actions builder = new Actions(driver);
    
    builder.moveToElement(element).click(element);
    builder.perform();
    
    0 讨论(0)
  • 2020-12-14 09:14

    Finally I found an answer that works with Firefox as well as Google Chrome.

    WebElement we = this.driver.findElement(By.id("size-btn"));
    
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", we);
    
    waitForElementPresent(By.xpath("//div[@id='size-btn' and contains(@class,'opened')]/span"));
    

    Thanks for reading me.

    0 讨论(0)
  • 2020-12-14 09:15

    I am not sure why are you using this Xpath, if you have freedom to change Xpath then record the element using selenium IDE and use Xpath::position from drop down list of target(it picks unique path relative to html header), it will solve problem of dynamic locator. And try below mentioned events.

    1- Use clickAt.

    2- Use fireevent(focus) and then click. Sometime it happens some element in back ground is getting loaded, when it gets loaded, focus move there hence elementNotVisible error.

    3- Use mouseDownRight.

    0 讨论(0)
  • 2020-12-14 09:16

    I have some solution, make a class with a robot put there TAB event keys, then call that class. What it does its like a back to focus to the page. For some razon the page lost focus and never find that botton.

       Robot robot;
        try {
            robot = new Robot();
            robot.keyPress(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_TAB);
    
        } catch (AWTException e) {e.printStackTrace();}
    
    0 讨论(0)
提交回复
热议问题