Element identification | Selenium Forum
M
Posted on 11/02/2017
Hi,
In framework you have taken an example of flipkart for login scenario.

currently in flipkart site a popup is displayed when login button is clicked.

I used below xpaths for identifying email text box but none are working.I checked the no. of frames..it displayed one..but in page source there is no iframe tag.please help in this.

1)driver.findElement(By.xpath("//input[@type='text']")).sendKeys("test@gmail.com");
2)driver.findElement(By.xpath("//input[starts-with(@type,'text')]")).sendKeys("abc@test.com");
3)driver.findElement(By.xpath("html/body/div[2]/div/div/div/div/div[2]/div/form/div[1]/input")).sendKeys("xyz@abc.com");

M
Replied on 11/02/2017

[quote:3763nndw]t displayed one..but in page source there is no iframe tag.[/quote:3763nndw]

iframe sometimes get created dynamically. so, it will not show up in the page source.

right click on the pop up to find if it's in the frame or not. and in selenium then switch to that frame.


M
Replied on 12/02/2017

Hi,
There is no 'this frame' when i right click on the popup and when i run without/with switching to frame I get nosuchelement exception error for email field. I have added attachments.pls suggest.


M
Replied on 12/02/2017

use this


[code:m4dr23il]package com.sample;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class test {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.get("https://www.flipkart.com/");
driver.findElement(
By.xpath("//*[@id='container']/div/header/div[1]/div[1]/div/ul/li[9]/a"))
.click();

List<WebElement> x = driver.findElements(By
.xpath("//input[@type='text']"));

x.get(1).sendKeys("qwe4rtyu");
driver.findElement(By.xpath("//input[@type='password']")).sendKeys(
"qwe4rtyu");
driver.quit();

}
}
[/code:m4dr23il]


M
Replied on 13/02/2017

Thank you it's working now...