Home > Software design >  How can I Click angular application button using selenium
How can I Click angular application button using selenium

Time:10-22

I can Login successfully but There is button "Start new booking" but my script doesn't click that button.

 import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 import com.paulhammant.ngwebdriver.ByAngular;
 import com.paulhammant.ngwebdriver.NgWebDriver;
 import org.openqa.selenium.support.ui.WebDriverWait;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.support.ui.Wait;

 public class NewClass {

 public static void main(String[] args) throws InterruptedException {
    
    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\Hp\\Downloads\\chromedriver_win32\\chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();
                    NgWebDriver ngWebDriver = new NgWebDriver(driver);
                    ngWebDriver.waitForAngularRequestsToFinish();
        driver.get("https://visa.vfsglobal.com/gbr/en/mlt/login");
                    driver.manage().window().maximize();
                    WebDriverWait wait = new WebDriverWait(driver, 30);
                    wait.until(ExpectedConditions.elementToBeClickable(By.id("onetrust-accept-btn-handler"))).click();
                    
                    // Login                     
                    
                    driver.findElement(By.id("mat-input-0")).sendKeys("*****@gmail.com");
                    driver.findElement(By.id("mat-input-1")).sendKeys("password");
                    
                    
                    driver.findElement(By.xpath("/html/body/app-root/div/app-login/section                /div/div/mat-card/form/button")).click();
                                 
                    driver.findElement(By.className("mat-button-wrapper")).click();
                                    
 }

}

Sample Image Here image

Help me How can i click that button. what is the problem , how can i solve?

CodePudding user response:

Try those line . actually working for me

Thread.sleep(10000);

driver.findElement(By.xpath("/html/body/app-root/div/app-dashboard/section/div/div[2]/button")).click();
  • Related