2

I am unable to click on the "Login" button provided in the header I am new to selenium, here is the code snippet

public class Muft_Mashwara_login {

    public WebDriver driver= null;

    @BeforeMethod
    public void startBrowser (){

        driver= new FirefoxDriver();
        driver.get("http://sqa.muftmashwara.be.vteamslabs.com/home");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        }   
    @Test
    public void Click()throws InterruptedException 
    {
        //Thread.sleep(3000);
        driver.findElement(By.xpath(".//*[@id='header2']/nav/div/ul/li/a")).click();
        WebElement loginTxt = driver.findElement(By.xpath("html/body/main/div/section/article[2]/div/div/form[1]/div[1]/div/input"));
        loginTxt.sendKeys("[email protected]");
    }
    @AfterMethod
    public void  Close(){
        driver.close();
    }
    }

it only works if I un-comment "Thread.sleep" I don't know how to implement dynamic wait in this case.

1 Answer 1

1

If you want to implement dynamic wait, try this:

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(elementToBeClickable(By.xpath(".//*[@id='header2']/nav/div/ul/li/a"))).click();

instead of this:

Thread.sleep(3000);
driver.findElement(By.xpath(".//*[@id='header2']/nav/div/ul/li/a")).click();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.