Cannot locate an element using By.xpath: selenium java

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot locate an element using By.xpath: selenium java

kiran kumar-5
Hi All,

I am unable to locate an element using SelenuimĀ 3.3.1 version. This is my code.

public WebDriver createPart() {

    try {

        driver.findElement(By.id("username")).sendKeys("502409373");
        driver.findElement(By.id("password")).sendKeys("Magic14Magic");
        driver.findElement(By.id("submitFrmShared")).click();
        //Thread.sleep(10000);
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
        Select dropCountry = new Select(driver.findElement(By.id("txtNewLocation")));
        dropCountry.selectByVisibleText("India");
        Thread.sleep(2000);
        driver.findElement(By.xpath("//button[@class='btn']/label")).click();
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);

        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='icon-button add']/span"))).click();
        driver.findElement(By.xpath("//div[@id='ENCActions']/a/label")).click();

        driver.findElement(By.xpath("//label[starts-with(text(),'Create Part...')]")).click();
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);

        String subWindowHandler = null;
        String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
        Set<String> handles = driver.getWindowHandles(); // get all window handles
        Iterator<String> iterator = handles.iterator();
        while (iterator.hasNext()){
            subWindowHandler = iterator.next();
            System.out.println(driver.switchTo().window(subWindowHandler).getTitle());
            System.out.println("k1");
        }
        System.out.println(driver.switchTo().window(subWindowHandler).getTitle());

        WebDriverWait wait = new WebDriverWait(driver, 10);

        WebElement element = driver.findElement(By.xpath("//select[@id='Type-Field']//following-sibling::div//div//input"));

        element.click();
        Thread.sleep(3000);
        element.sendKeys(Keys.BACK_SPACE);
        Thread.sleep(3000);

        element.sendKeys("Subassy");
        Thread.sleep(4000);

        driver.findElement(By.xpath("//div[@data-value='Subassy']")).click();
        driver.findElement(By.xpath("//span[text()='Description']//parent::td//following-sibling::td//textarea")).sendKeys("Testing");
        driver.findElement(By.xpath("//option[text()='BioSc-DS-Chemical']//parent::select")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("//option[text()='BioSc-DS-Chemical']")).click();
        driver.findElement(By.xpath("//a[text()='Done']")).click();
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);

        System.out.println(driver.switchTo().window(parentWindowHandler).getTitle());       
        String subWindowHandler1 = null;
        Set<String> handles1 = driver.getWindowHandles(); // get all window handles
        Iterator<String> iterator1 = handles1.iterator();
        while (iterator1.hasNext()){
            subWindowHandler1 = iterator1.next();
            System.out.println(driver.switchTo().window(subWindowHandler1).getTitle());
            System.out.println("k2");
        }
        System.out.println(driver.switchTo().window(parentWindowHandler).getTitle());
        element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='Part Details']")));
        element.click();


    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return driver;

}
This is the stack trace.
3DEXPERIENCE Platform
k1
<title>Create Part<title>Create Part
k1
<title>Create Part<title>Create Part
3DEXPERIENCE Platform
3DEXPERIENCE Platform
k2
<title>Create Part<title>Create Part
k2
3DEXPERIENCE Platform
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected 
condition failed: waiting for element to be clickable: By.xpath:      
//a[@title='Part Details'] (tried for 10 second(s) with 500 MILLISECONDS 
interval)
at 


org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232)
    at selenium_test.TestClass.createPart(TestClass.java:126)
    at selenium_test.TestClass.main(TestClass.java:142)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //a[@title='Part Details']

HTML code of the Part Details link:

<div class="tabcontent">
<a class="tablink" href="javascript:void(0);" title="Part Details" onclick="tvcTabPage_tabClicked(this,true)">Part Details</a>
<a href="javascript:void(0);" class="closetab" onclick="tvcTabPage_tabClosed(this)" title="Close Tab"></a>
</div>

I am clicking a command on main page. It gives a popup form. After filling the popup form and clicking on done,
popup gets closed automatically and main page shows whole new page. I am unable to find Part Details link in the main page.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fb5d72f4-5243-4216-a48d-1b22b136267a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Cannot locate an element using By.xpath: selenium java

Brenda Granados
Are you sure the link is visible by the time the Webdriver looks for it? Your xpath looks correct.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7c9a0485-20f2-4ef2-9c61-f20d1c05fe73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.