Not able to click on button in java selenium?

后端 未结 2 1685
离开以前
离开以前 2021-01-22 22:36

HTML code:

相关标签:
2条回答
  • 2021-01-22 23:20

    You can try and get it by cssSelector instead. As far as I remember by className is only for one class.

    driver.findElement(By.cssSelector(".btn.btn-main.dropdown-toggle")).click();
    
    0 讨论(0)
  • 2021-01-22 23:22

    Executing a click via webdriver has sometime unexpected behaviors.If its not working then alternate way JavascriptExecutor class to do this. Its always preferable to use click() method of the WebElement.

    WebElement element = driver.findElement(By.cssSelector(".btn.btn-main.dropdown-toggle"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element);
    
    0 讨论(0)
提交回复
热议问题