If you want to find an element using the id
attribute value of a link element, it's recommended to use By.id()
instead, like this:
new WebDriverWait(driver, 50).until(ExpectedConditions.elementToBeClickable(By.id("expTo"))).click();
Alternatively, if you prefer to locate the element using By.linkText()
, you should provide the exact innerText
of the link element, such as:
new WebDriverWait(driver, 50).until(ExpectedConditions.elementToBeClickable(By.linkText(" Export To "))).click();
Please note: Based on the extra spaces in the innerText
of the link element in your HTML, if you are using By.linkText()
, you must include those extra spaces as well. In case of extra spaces, you can also consider using By.partialLinkText()
to locate the element by visible text without spaces, like this:
new WebDriverWait(driver, 50).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Export To"))).click();
Edited:
The element is within an iframe, Saurabh. How can I attempt to click it?
If the element is nested inside an iframe
, you must switch to that iframe
before identifying the element, as shown below:
WebDriverWait wait = new WebDriverWait(driver, 50);
//Switch to the iframe
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("iframe id or name"));
//Locate and click the desired element
wait.until(ExpectedConditions.elementToBeClickable(By.id("expTo"))).click();
//Once done with operations inside the iframe, switch back to the default content for further actions
driver.switchTo().defaultContent();