When using Selenium for website that you don't own, NEVER rely on IDs or classes since they often change, especially for google's websites.
Best way to search for it is to find the element that presents the text that you know is wrote on the button (in this case Ask to join) and then get all the parents in a loop and check if some of them are buttons.
Like this:
WebElement buttonTextElement = browser.find_elements_by_xpath("//*[contains(text(), 'Ask to join')]")
then launch this javascript code in a cycle and stop it only if parent role attribute is equal to "button" or tag is "button"
WebElement parent = buttonTextElement;
WebElement parent = browser.execute_script("return arguments[0].parentNode;", parent)
Then click().
I've wrote for u a fully working code in Java. I've used chromedriver version 85.
I shouldn't paste a whole code, but i'll do it for u :)
I saw that "Next" Button is the first parent so you don't need to go recursive.
PS: Since i visited the italian webpage, make sure that the strings "Next" and "Ask to Join" are right char for char. Change them if u need to.
import java.util.ArrayList;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
String email = "Your Google Email";
String pass = "Your Google Password";
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// You need this to stop the page from askin u for mic
options.addArguments("--use-fake-ui-for-media-stream");
WebDriver driver = new ChromeDriver(options);
//Login to Google
driver.get("https://accounts.google.com/login");
ArrayList<WebElement> emailinput = new ArrayList<WebElement>();
ArrayList<WebElement> spans = new ArrayList<WebElement>();
emailinput = (ArrayList<WebElement>) driver.findElements(By.tagName("input"));
//Get all spans in page
spans = (ArrayList<WebElement>) driver.findElements(By.tagName("span"));
for(int i = 0; i < emailinput.size(); i++) {
if(emailinput.get(i).getAttribute("type").equals("email")) { emailinput.get(i).sendKeys(email); break; }
}
for(int i = 0; i < spans.size(); i++) {
if(spans.get(i).getText().equals("Next")) {
WebElement parent = (WebElement) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].parentNode;", spans.get(i)); parent.click(); break; }
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<WebElement> passinput = (ArrayList<WebElement>) driver.findElements(By.tagName("input"));
for(int i = 0; i < passinput.size(); i++) {
if(passinput.get(i).getAttribute("type").equals("password")) { passinput.get(i).sendKeys(pass); break; }
}
spans = (ArrayList<WebElement>) driver.findElements(By.tagName("span"));
for(int i = 0; i < spans.size(); i++) {
if(spans.get(i).getText().equals("Next")) {
WebElement parent = (WebElement) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].parentNode;", spans.get(i)); parent.click(); break; }
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Create a Meet room and put here its URL
driver.navigate().to("https://meet.google.com/dxz-dbwt-tpj");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
spans = (ArrayList<WebElement>) driver.findElements(By.tagName("span"));
for(int i = 0; i < spans.size(); i++) {
if(spans.get(i).getText().equals("Ask to Join")) {
WebElement parent = (WebElement) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].parentNode;", spans.get(i)); parent.click(); break; }
}
}
}