简体   繁体   中英

Selenium tool is not able to identify the element by xpath

I am trying to automate the naukri.com application.

After the successful login I need to search the jobs based on the skills, location, experience and salary.With the help of xpath I was able to identify the first element(Skills, Designation, companies).Below is the xpath code for the same

//div[@id='skill']

However, when I run the script, the element is not identified and the script fails.And just to add the element doesn't fall in any frame.Please kindly help me to resolve the issue and screen print attached for reference 在此处输入图片说明

--Here is the code for reference--

public class naukri {
@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 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();
     }
 }
 }
 driver.switchTo().window(parent);

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

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

    }


    driver.findElement(By.xpath("//a[@id='uSel']")).click();
             driver.findElement(By.xpath("//input[@id='uLogin']")).sendKeys("anand_qa");
    driver.findElement(By.xpath("//input[@id='pLogin']")).clear();
    driver.findElement(By.xpath("//input[@id='pLogin']")).sendKeys("test@1234");
    driver.findElement(By.xpath("//button[@class='blueBtn']")).click();
     driver.switchTo().window(parent);

     Thread.sleep(5000);
     WebElement element = driver.findElement(By.xpath("//a[@title='Search Jobs']"));
     Actions action = new Actions(driver);
     action.moveToElement(element).build().perform();
     driver.findElement(By.xpath("//a[@title='Jobs by Skill']")).click();
     Thread.sleep(5000);

     List<String> browserTabs = new ArrayList<String> (driver.getWindowHandles());

     driver.switchTo().window(browserTabs.get(1));
     //Below are the two elements which are not identified by the tool but the same gets identified thru fire bug 
     driver.findElement(By.xpath("//div[@id='skill']")).sendKeys("testing");
     driver.findElement(By.xpath("//div[@id='location']")).sendKeys("bangalore");

}

This works for me:

Class<?> cls = Class.forName("org.openqa.selenium.firefox.FirefoxDriver");
WebDriver driver = (WebDriver) cls.newInstance();
driver.get("http://naukri.com");
WebElement webElement = driver.findElement(By.xpath("//div[@id='skill']"));
System.out.println(webElement.isEnabled());

Output is:

true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM