0
votes

I have a problem , click button in dialog forms in google. This is my code :

@BeforeEach
public void startDriver() throws InterruptedException {
    // Start Chrome browser
    System.setProperty("webdriver.chrome.driver", "C:\\gecko\\chrome\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.get("https://www.google.pl/?gws_rd=ssl");
}

@Test
@DisplayName("Test strony google")
public void testGoogle() throws InterruptedException, IOException {
    System.out.println("Rozpoczecie testu strony google");
    ModelStatistic modelStatistic = new ModelStatistic();
    System.out.println(modelStatistic.getTimestamp());
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    Thread.sleep(4000);
    WebElement agree = driver.findElement(By.id("introAgreeButton"));
    agree.click();
    Thread.sleep(3000);
    WebElement name = driver.findElement(By.cssSelector("input[name='q']"));
    name.sendKeys("Kamil Surma");
}

Selenium Cant's see Webelement agree.

I agree
2
Hi, what kind of error are you getting? - Arundeep Chohan
Which is Before you continue button on Google Home Page? - DebanjanB
no such element: Unable to locate element: {"method":"css selector","selector":"#introAgreeButton"} (Session info: chrome=85.0.4183.83) - Kamil Surma
Before you continue is a name of dialog form when I write google.pl/?gws_rd=ssl it show , but I want to click button "I Agree" WebElement agree = driver.findElement(By.id("introAgreeButton")); - Kamil Surma

2 Answers

1
votes

Add this: driver.switchTo().frame(0);

before that: WebElement agree = driver.findElement(By.id("introAgreeButton"));

The button is in iframe and driver can't find it.

0
votes

You can also add this: driver.wait(until.ableToSwitchToFrame(0)); instead Thread.sleep(4000);driver.switchTo().frame(0);

It will switch automatically