This is the code I am trying to execute
public WebDriver createPart() {
try {
driver.findElement(By.id("username")).sendKeys("502409373");
driver.findElement(By.id("password")).sendKeys("Magic14Magic");
driver.findElement(By.id("submitFrmShared")).click();
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");
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button[@class='btn']/label")).click();
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.findElement(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 parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window
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.switchTo().window(parentWindowHandler);
driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
wait = new WebDriverWait(driver, 60);
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 html code of the element, I am unable to find.
<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>
This is the stack trace
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 60 second(s) with 500 MILLISECONDS
interval)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an
element using By.xpath: //a[@title='Part Details']
Even though I have used wait statement. I am unable to locate the element. I have verified the xpath using chrome xpath. Please help me resolving my issue. Selenium version:3.3.1. The actual flow is, I am clicking a link in main page which results a popup consisting a form. After filling the form and clicking on done, popup gets closed automatically and main page gets refreshed and a new page is opened. Now, I am trying to click on the Part Details link in the new main page which is not working.
I have added this peice of code to find the right window handler.
subWindowHandler = null;
Set<String> handles1 = driver.getWindowHandles(); // get all window handles
iterator = handles1.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
driver.switchTo().window(subWindowHandler);
element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Part Details']")));
System.out.println("KK1");
}
Giving me the output:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected
condition failed: waiting for visibility of element located by By.xpath:
//a[@title='Part Details'] (tried for 10 second(s) with 500 MILLISECONDS
interval)
Here, required 'Part Details' element is located in a frame which I have included in code. But, i am unable to locate the element inside the frame. This is my modified code.
System.out.println(driver.switchTo().window(parentWindowHandler).getTitle());
driver.switchTo().frame("content");
driver.switchTo().frame("detailsDisplay");
driver.findElement(By.xpath("//a[@title='Part Details']")).click();
But I am facing this error.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no
such element: Unable to locate element:
{"method":"xpath","selector":"//a[@title='Part Details']"}
I have attached my screenshot of the html code. HTML screenshot
element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='Part Details']")));afterdriver.switchTo().window(parentWindowHandler);Now, as per your question update you wanted us to help you in solvingelement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Part Details']")));afterdriver.switchTo().window(subWindowHandler);- DebanjanB