Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 匹配表中的文本并使用SeleniumWebDriver单击它_Xpath_Selenium Webdriver - Fatal编程技术网

Xpath 匹配表中的文本并使用SeleniumWebDriver单击它

Xpath 匹配表中的文本并使用SeleniumWebDriver单击它,xpath,selenium-webdriver,Xpath,Selenium Webdriver,我有一个表,其中有一列名为“state”。我必须找到并点击与该栏中文本“closed successful”匹配的链接。该列中每个单元格的xpath为 "//*[@id='TicketID_xxxxxx']/td[7]/div 其中xxxxxx是票数。那么,我如何找到具有不同xpath值的匹配文本,并使用SeleniumWebDriver单击它呢。请帮忙 (可选-我必须单击该元素,单击“上一步”并找到下一个具有相同匹配文本的元素)嗨,Sanket Patel,请按以下方式操作 driver.

我有一个表,其中有一列名为“state”。我必须找到并点击与该栏中文本“closed successful”匹配的链接。该列中每个单元格的xpath为

 "//*[@id='TicketID_xxxxxx']/td[7]/div
其中xxxxxx是票数。那么,我如何找到具有不同xpath值的匹配文本,并使用SeleniumWebDriver单击它呢。请帮忙


(可选-我必须单击该元素,单击“上一步”并找到下一个具有相同匹配文本的元素)

嗨,Sanket Patel,请按以下方式操作

driver.get(yourWebPageLInk); // link to your web-table web page

    // take all of the element under Column "State" inside list

    List<WebElement> columVal =  driver.findElements(By.xpath("//*[starts-with(@id,'TicketID_')]/td[7]/div"));
    // count the size of the list to match with the size of the column state
    System.out.println("Size of the contents in the column state is : " +columVal.size());

    // now for matching one of the content and then performing some action please
    // start a for loop

    String oneVal = "closed successful";
    for(int i=0;i<columVal.size();i++){
        System.out.println("Content text is : " + columVal.get(i).getText());
        // match the content here in the if loop
        if(columVal.get(i).getText().equals(oneVal)){
            // perform action
            columVal.get(i).click();
        }
    }
driver.get(你的网页链接);//链接到web表网页
//获取列表中“状态”列下的所有元素
List columVal=driver.findelelements(By.xpath(“/*[以(@id,'TicketID')]]/td[7]/div开头”);
//计算列表的大小以与列状态的大小匹配
System.out.println(“列状态中的内容大小为:”+columVal.Size());
//现在要匹配其中一个内容,然后执行一些操作,请
//启动for循环
字符串oneVal=“关闭成功”;

对于(inti=0;iHi Sanket Patel,请按以下方式操作

driver.get(yourWebPageLInk); // link to your web-table web page

    // take all of the element under Column "State" inside list

    List<WebElement> columVal =  driver.findElements(By.xpath("//*[starts-with(@id,'TicketID_')]/td[7]/div"));
    // count the size of the list to match with the size of the column state
    System.out.println("Size of the contents in the column state is : " +columVal.size());

    // now for matching one of the content and then performing some action please
    // start a for loop

    String oneVal = "closed successful";
    for(int i=0;i<columVal.size();i++){
        System.out.println("Content text is : " + columVal.get(i).getText());
        // match the content here in the if loop
        if(columVal.get(i).getText().equals(oneVal)){
            // perform action
            columVal.get(i).click();
        }
    }
driver.get(yourWebageLink);//链接到web表网页
//获取列表中“状态”列下的所有元素
List columVal=driver.findelelements(By.xpath(“/*[以(@id,'TicketID')]]/td[7]/div开头”);
//计算列表的大小以与列状态的大小匹配
System.out.println(“列状态中的内容大小为:”+columVal.Size());
//现在要匹配其中一个内容,然后执行一些操作,请
//启动for循环
字符串oneVal=“关闭成功”;
对于(int i=0;i您可以使用
text()
方法

String text = "someText";
driver.findElement(By.xpath("//div[contains(text(), '" + text + "')]")).click();
或使用
css选择器

String text = "someText";
driver.findElement(By.cssSelector("div:contains('" + text + "')")).click();
您可以使用
text()
方法

String text = "someText";
driver.findElement(By.xpath("//div[contains(text(), '" + text + "')]")).click();
或使用
css选择器

String text = "someText";
driver.findElement(By.cssSelector("div:contains('" + text + "')")).click();

您可以将TableDriver扩展用于Selenium WebDriver的以下情况。()。如果有关于该表的更详细信息,这将非常有用,但是如果我们假设该表有一列“link”,其中包含您需要单击的链接,并且我们假设主表元素的id为“tabelId”你可以这样做:

Table Table=Table.create(driver.findElement(By.id(“tableId”));
WebElement元素=table.findCell(“state=closed successful”,“link”).element;
element.findElement(按.tagName(“a”))。单击();

在这种情况下,您可以使用TableDriver扩展来Selenium WebDriver。(。如果有关于该表的更多详细信息,这将非常有用,但是如果我们假设该表有一列“link”,其中包含您需要单击的链接,并且我们假设主表元素的id为“tabelId”你可以这样做:

Table Table=Table.create(driver.findElement(By.id(“tableId”));
WebElement元素=table.findCell(“state=closed successful”,“link”).element;
element.findElement(按.tagName(“a”))。单击();

请添加一些HTML,以便人们可以帮助您。您在Selenium中使用的是什么语言绑定?我应该添加HTML的哪一部分,我正在使用java和Selenium。您尝试处理的表的一些示例,有几行。这是第7行,名为state的列,具有不同的值,如“new”、“open”、“closed successful”。我必须匹配文本“closed successful”并单击它。我提到了列单元格的xpath。为什么要编写td[7]但是关于第7行呢?请添加一些HTML以便人们可以帮助您。您使用的是什么语言绑定Selenium?我应该添加HTML的哪一部分,我正在使用java和Selenium。您尝试处理的表的一些示例,有几行。它是第7行,名为state的列,具有不同的值,如“new”、“open”,“closed successful”(关闭成功)。我必须匹配文本“closed successful”(关闭成功)并单击它。我提到了列单元格的xpath。为什么要写td[7],但要说第7行?我很高兴这有助于您将其标记为您的答案我很高兴这有助于您将其标记为您的答案