I am trying to automate Naukari.com so that it gets updated daily on its own instead of me visiting the website daily to do it My script is as follows:
public class NaukariUpdater {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","./driver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.naukri.com/");
driver.getTitle();
String mainWindowTitle = driver.getTitle();
String mainWindowID = driver.getWindowHandle();
Set<String> s = driver.getWindowHandles();
for (String handleID : s)
{
driver.switchTo().window(handleID);
System.out.println(driver.getTitle());
String windowID = driver.getTitle();
if (!windowID.equals(mainWindowTitle))
{
driver.close();
}
}
driver.switchTo().window(mainWindowID);
driver.findElement(By.xpath("(//div[text()='Login'])[1]")).click();
driver.findElement(By.xpath("//a[.='Google']")).click();
Set<String> window = driver.getWindowHandles();
System.out.println();
for (String handleID : window)
{
driver.switchTo().window(handleID);
String windowTitle = driver.getTitle();
System.out.println(windowTitle+"\t"+mainWindowTitle);
if (!windowTitle.equals(mainWindowTitle))
{
System.out.println("in IF");
driver.switchTo().window(handleID);
break;
}
}
System.out.println("out of switching "+driver.getTitle());
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement webElement = driver.findElement(By.xpath("//input[@id='identifierId']"));
wait.until(ExpectedConditions.visibilityOf(webElement));
LoginPOM POM = new LoginPOM(driver);
WebElement logIN = POM.getLogIn();
logIN.sendKeys("Sorry type in your own email ID bro");
WebElement nextBtn = POM.NextButton();
nextBtn.click();
wait.until(ExpectedConditions.visibilityOf(POM.getPassword()));
WebElement pswd = POM.getPassword();
pswd.sendKeys("Sorry type in your own password bro");
nextBtn.click();
}
}
This is the POM
package naukariLoginPOM;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class LoginPOM {
public LoginPOM(WebDriver driver)
{
PageFactory.initElements(driver , this);
}
@FindBy(xpath = "//input[@id='identifierId']")
private WebElement LogIn;
public WebElement getLogIn()
{
return LogIn;
}
@FindBy(xpath = "//input[@type='password']")
private WebElement Pswd;
public WebElement getPassword()
{
return Pswd;
}
@FindBy(xpath = "//content[.='Next']")
private WebElement NextBtn;
public WebElement NextButton()
{
return NextBtn;
}
}
I don't get where I made the mistake every thing seems to run fine but yet I get error 1001 in the end how can I resolve it? Thank you in advance
Aucun commentaire:
Enregistrer un commentaire