cat-ninja
cat-ninja

Reputation: 39

How to get an xpath of element in the table

I'm getting started with Selenium webdriver (newbie :D). How i can get an xpath of element in the table? I have tried to see the source code of page in chrome, after - pick element and get xpath of it. Selenium webdriver tells me that he can't find an element with this xpath.

Link of the page: http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellList

How i can paste characters to textBox, for example? I tried to use this code:

UPD:

 @org.junit.Test
    public void getStarted(){
        System.setProperty("webdriver.chrome.driver", "/Users/fedor/Desktop/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.get("http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellList");

        WebElement t = driver.findElement(By.xpath(".//tr[td[contains(text(), 'First Name')]]//input"));

        t.clear();
        t.sendKeys("test1111");

    }

UPD 2: Problem was in miss of implicit wait before finding element. This code fixed it for me:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Upvotes: 1

Views: 2154

Answers (1)

Saurabh Gaur
Saurabh Gaur

Reputation: 23835

For example from the given link.

If you want to enter text into First Name textBox try using below xpath which would locate appropriate textBox using text :-

.//tr[td[normalize-space() = 'First Name:']]//input

or

.//tr[td[contains(text(), 'First Name')]]//input

Upvotes: 1

Related Questions