gpt4 book ai didi

java - 无法使用 selenium Webdriver 识别 naukri.com 应用程序的登录按钮

转载 作者:行者123 更新时间:2023-11-30 08:08:59 25 4
gpt4 key购买 nike

我正在尝试自动化 naukri.com 应用程序,作为其中的一部分,当我启动该网站时,它基本上会显示一组弹出窗口,在我继续登录该应用程序之前需要将其关闭。此特定功能已由关闭所有弹出窗口的代码处理,当我继续单击登录按钮时,未识别登录按钮链接并且脚本失败。如果我注释弹出窗口代码,则识别登录按钮.请找到以下相同的代码并帮助我解决问题

   public class naukri {
WebDriver driver = new FirefoxDriver();

@Test
public void pagelaunch() throws InterruptedException{
driver.get("http://www.naukri.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String parenthandle = driver.getWindowHandle();
String parent = driver.getWindowHandle();

//close all the pop ups
Set<String> pops=driver.getWindowHandles();
Iterator<String> it =pops.iterator();
while (it.hasNext()){
String popupHandle=it.next().toString();
if(!popupHandle.contains(parent))
{
driver.switchTo().window(popupHandle);
System.out.println("Pop Up Title: "+ driver.switchTo().window(popupHandle).getTitle());
driver.close();
}
}

System.out.println("the system handle is"+parenthandle);

//to click on login button and proceed to login to the application
driver.findElement(By.xpath("//a[@title='Jobseeker Login']")).click();
Thread.sleep(5000);

for(String winhandle:driver.getWindowHandles())
{
driver.switchTo().window(winhandle);
}

driver.findElement(By.xpath("//a[@id='uSel']")).click();
driver.findElement(By.xpath("html/body/div[8]/div[2]/div[2]/form/div[4]/div[2]/input")).sendKeys("anand_qa");
driver.findElement(By.xpath("html/body/div[8]/div[2]/div[2]/form/div[5]/div[2]/input")).sendKeys("test1234");
driver.findElement(By.xpath("//div[8]/div[2]/div[2]/form/div[7]/button")).click();
driver.switchTo().window(parenthandle);
}
}

最佳答案

 public class naukri {
WebDriver driver = new FirefoxDriver();
@Test
public void pageLaunch() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.naukri.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String parenthandle = driver.getWindowHandle();
String parent = driver.getWindowHandle();

//close all the pop ups
Set<String> pops=driver.getWindowHandles();
{
Iterator<String> it =pops.iterator();
while (it.hasNext()) {

String popupHandle=it.next().toString();
if(!popupHandle.contains(parent))
{
driver.switchTo().window(popupHandle);
System.out.println("Pop Up Title: "+ driver.switchTo().window(popupHandle).getTitle());
driver.close();
}
}
}
System.out.println("the system handle is"+ driver.switchTo().window(parenthandle).getTitle());

//to click on login button and proceed to login to the application
driver.findElement(By.xpath("//a[@id='login_Layer']")).click();
Thread.sleep(5000);
/*for (String winhandle:driver.getWindowHandles())
{
driver.switchTo().window(winhandle);
}*/

driver.findElement(By.xpath("//a[@id='uSel']")).click();
driver.findElement(By.xpath("//form[@id ='lgnFrm']/div[4]/div[2]/input[@id='uLogin']")).sendKeys("anand_qa");
driver.findElement(By.xpath("//form[@id ='lgnFrm']/div[5]/div[2]/input[@id='pLogin']")).sendKeys("test1234");
driver.findElement(By.xpath("//form[@id='lgnFrm']/div[7]/button")).click();
}
}

关于java - 无法使用 selenium Webdriver 识别 naukri.com 应用程序的登录按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com