Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, this is definitely possible. See this:</p> <pre><code>// Find the outer element. WebElement outer = driver.findElement(By.anything("whatever")); // This doesn't work, it searches the whole page for the XPath expression. WebElement inner = outer.findElement(By.xpath("//some/nasty/xpath")); // This works! It takes the outer element as root. WebElement inner = outer.findElement(By.xpath(".//some/nasty/xpath")); </code></pre> <p>Therefore, if I understood your need well, your XPath expression needs to look like this:</p> <pre><code>By.xpath("(.//tbody)[" + j + "]//div[text()=\"" + collector + "\"])") </code></pre> <hr> <p><strong>EDIT</strong> (Holy cow, that's a lot of HTML and only a small amount of it is actually needed :).)</p> <p>Now that I caught what you're after, I think you don't need this approach at all. Try this instead:</p> <pre><code>WebElement row = driver.findElement(By.xpath("id('CollectorQoSPerformanceMetricsgrid')//div[contains(@class,'x-grid3-row x-unselectable-single') and .//u[text()='" + collector + "']]")); </code></pre> <p>Only the XPath expression:</p> <pre><code>id('CollectorQoSPerformanceMetricsgrid') //div[contains(@class,'x-grid3-row x-unselectable-single') and .//u[text()='" + collector + "'] ] </code></pre> <p>Taken apart:</p> <pre><code>FIND ELEM WITH ID = 'CollectorQoSPerformanceMetricsgrid' id('CollectorQoSPerformanceMetricsgrid') FIND ALL DIV ELEMS THAT CONTAIN 'x-grid3-row x-unselectable-single' IN @CLASS //div[contains(@class,'x-grid3-row x-unselectable-single') AND HAVE AN &lt;U&gt; DESCENDANT WITH TEXT EQUAL TO collector VARIABLE and .//u[text()='" + collector + "'] ] </code></pre> <p>This finds you only the single row you need with a single command.</p> <p>If you rather want to stick with your current solution, try:</p> <pre><code>String rowsXpath = "id('CollectorQoSPerformanceMetricsgrid')//div[contains(@class, 'x-grid3-row x-unselectable-single')]"; List&lt;WebElement&gt; rows = driver.findElements(By.xpath(rowsXpath)); boolean foundCollector = false; for(WebElement row : rows) { if(!row.findElements(By.xpath(".//u[text()='" + collector + "']")).isEmpty()) { foundCollector = true; break; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload