I tried xpath "//input[@type='text'][1]"
inorder to get unique element with same xapths, but still getting result with 2 nodes.
Is there any way I can write the xpath to identify uniquely in Java.
CodePudding user response:
The Element you are trying to find is in an Iframe
And the input
tag is unique for that iframe
.
// Imports Required for Explicit wait:
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
driver.get("http://demo.automationtesting.in/Frames.html");
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("singleframe")));
wait.until(ExpectedConditions.elementToBeClickable(By.tagName("input"))).sendKeys("Sample Text");
Update
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//div[@id='Multiple']/iframe")));
String output = driver.findElement(By.xpath("//*[contains(text(),'Your browser does not support iframes')]")).getAttribute("innerText");
System.out.println(output);
<p>Your browser does not support iframes.</p>
CodePudding user response:
You were almost there.
The below xpath should get the job done. This is basically xpath indexing :
(//input[@type='text'])[1]
for second element :
(//input[@type='text'])[2]