Search code examples
javaseleniumxpathautomationnosuchelementexception

I can't find the button via Selenium Java


I've tried to find it through cssSelector and xPath but displays NoSuchElementException anyway

WebElement element = driver.findElement(By.cssSelector("button[class='btn btn-primary c-schedule-story-button ']"));
element.click();

Screenshot is here


Solution

  • driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
    WebElement element = driver.findElement(By.cssSelector("button..c-schedule-story-button"));
    element.click();
    

    Its inside an iframe , you have to switch to that first

    you have to switch to defaultcontent if you want to interact again with outside elements

    driver.switchTo().defaultContent()