简体   繁体   English

如何获取表中元素的xpath

[英]How to get an xpath of element in the table

I'm getting started with Selenium webdriver (newbie :D). 我开始使用Selenium Webdriver(newbie:D)。 How i can get an xpath of element in the table? 我如何获取表中元素的xpath? I have tried to see the source code of page in chrome, after - pick element and get xpath of it. 我试图在chrome中查看chrome页面的源代码-选择元素并获取它的xpath。 Selenium webdriver tells me that he can't find an element with this xpath. Selenium Webdriver告诉我,他无法使用此xpath找到元素。

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

How i can paste characters to textBox, for example? 例如,我如何将字符粘贴到textBox? I tried to use this code: 我尝试使用此代码:

UPD: 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. UPD 2:问题在于找不到元素之前隐式等待。 This code fixed it for me: 这段代码为我修复了它:

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

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 :- 如果要在“ 名字” textBox框中输入文本,请尝试在xpath使用文本查找合适的textBox

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

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM