This is the code I am trying to execute
public WebDriver createPart() {
try {
driver.findElement(By.id(\"username\")).sendKeys(\"502409373\");
your parentWindowHandler
should not be correct, you fetch it at wrong time point.
Try move below code line to the first line in the try
block
try {
String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
Change visibilityOfElementLocated
instead of elementToBeClickable
.
You can directly find the webeelement, and then click on it as shown below:
element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Part Details']")));
Once switched to parent window, try to refresh the page then find the element as given below. It may solve your issue.
driver.switchTo().window(parentWindowHandler);
driver.navigate().refresh();
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();
To invoke click()
on the link with text as Part Details you need to induce WebDriverWait and invoke click()
as follows :
linkText :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Part Details"))).click();
cssSelector :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.tablink[title='Part Details']"))).click();
xpath :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='tablink' and @title='Part Details']"))).click();