12.6 C
New York
Wednesday, October 16, 2024

selenium webdriver – Factor positioned when put in a single take a look at case however not positioned when put in separate take a look at case


I’m in a bizarre state of affairs the place I discovered that my component is positioned after I wrote in a single take a look at case. However as quickly as I put that component in a separate take a look at case, Unable to find component Exception is been given.

That is the code which isn’t working.

@Check
public void login() throws Exception {


    getdriver().get("http://10.6.6.132:3000/login");

    EyeGuide_Login_Pom lg=PageFactory.initElements(getdriver(), 
    EyeGuide_Login_Pom.class);
    lg.loginEyeguide();
    Thread.sleep(5000);
    Assert.assertEquals(getdriver().getTitle(),"EyeGuide");
    //Assert.assertEquals(getdriver().getCurrentUrl(),lg.url);
    Thread.sleep(2000);
}

@Check
public void deactivateorg() throws Exception {
    organizationpagepom or=PageFactory.initElements(getdriver(), organizationpagepom.class);
    or.deactorg();
}

}

That is the code which works as no separate take a look at case is added.

@Check
public void login() throws Exception {


    getdriver().get("http://10.6.6.132:3000/login");

EyeGuide_Login_Pom lg=PageFactory.initElements(getdriver(), 
    EyeGuide_Login_Pom.class);
lg.loginEyeguide();
Thread.sleep(5000);
Assert.assertEquals(getdriver().getTitle(),"EyeGuide");
//Assert.assertEquals(getdriver().getCurrentUrl(),lg.url);
Thread.sleep(2000);
}


    organizationpagepom or=PageFactory.initElements(getdriver(), 
    organizationpagepom.class);
or.deactorg();


}

Beneath is the pom I’m utilizing.

public class organizationpagepom extends Basetest  {
//  organizationpagepom(WebDriver driver){
//      tremendous(driver);
//  }
@FindBy(css="a[href="https://sqa.stackexchange.com/organization"]")
WebElement manageorg;


@FindAll(@FindBy(xpath="//*[text()='Deactivate']"))
Record deactorglinks;
@FindAll(@FindBy(xpath="//*[@class="ant-btn downloadBtn ant-dropdown- 
    trigger"]"))
Record actdeactseldrpdown;
@FindAll(@FindBy(xpath="//*[@class="ant-dropdown-menu-item"]"))
Record activeinactiveddownvalues;


public void deactorg() throws Exception
{
    manageorg.click on();
    Thread.sleep(2000);
    deactorglinks.get(0).click on();
    Thread.sleep(2000);
    actdeactseldrpdown.get(1).click on();
    Thread.sleep(2000);
    activeinactiveddownvalues.get(0).click on();
    Thread.sleep(3000);
}

    }

EyeGuide_Login_Pom code is as follows.

public class EyeGuide_Login_Pom {



    @FindBy(identify="phoneInput")
    WebElement un;
    @FindBy(xpath="//*[@placeholder="Password"]")
    WebElement pw;
    @FindBy(css="button[type="button"]")
    WebElement signinbtn;


    public void loginEyeguide() 
    {
        un.clear();
        un.sendKeys("tdladmin");
        pw.sendKeys("tremendous");
        signinbtn.click on();

    }



}

I’ve taken the WebDriver object as non-public and I used getdriver() technique to entry the non-public variable. I do not know why this subject is been popped out.
The code of WebDriver entry is as follows.

public class Basetest {
    non-public WebDriver driver;


    @BeforeTest
    public void setbrowserproperties()
    {
        System.setProperty("webdriver.chrome.driver","F:Browser Chrome Driver recordsdatachromedriver.exe");
        this.driver=new ChromeDriver();
        getdriver().handle().window().maximize();
    }

    @AfterTest
    public void closedriver()
    {
        getdriver().shut();
    }
    protected WebDriver getdriver() {
        return driver;
    }

}

Please assist me as I’m not capable of finding any resolution. Beneath is the error that I get.

org.openqa.selenium.NoSuchElementException: no such component: Unable to find component: {"technique":"css selector","selector":"a[href="https://sqa.stackexchange.com/organization"]"}

Replace: I additionally tried this but it surely did not work and did not give me any failure.

public organizationpagepom oged() throws Exception {    
    //getdriver().handle().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    organizationpagepom oot=PageFactory.initElements(getdriver(), organizationpagepom.class); 
    oot.deactorg(); 
    return oot; 
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles