1

I was having a hard time using Selenium web driver to find the label text for the below scenario.

<tr id="row"> 
<td width="148" height="22" align="left"> 
<b> Label Text</b> 
</td> </tr>

How do I get the Label Text using webdriver ?

Thanks in advance.


Thanks for the reply. I think I should have been more specific. I have a list of td tags inside the tr tag. For eg:

<tr id="row"> 
<td width="148" height="22" align="left"> 
<b> Label Text 1</b> 
<td width="148" height="22" align="left"> 
<b> Label Text 2</b> 

<td width="148" height="22" align="left"> 
<b> Label Text 3</b> 
</td> </tr>

driver.findElement(By.id("row")).getText() would retrieve me all of those label values. Can I get the label value based on the location in the page ? Thanks.

1

4 Answers 4

2
driver.findElement(By.id("row")).getText();
Sign up to request clarification or add additional context in comments.

Comments

1

You can loop through all required labels one by one by using the following code -

List<WebElement> list = driver.findElements(By.xpath("//*[@id='row']/td/b"));

for(int i=0;i<list.size;i++){

   list.get(i).getText();

  }

I hope that this answers your problem.

Comments

0

To get a value via its location you can use something like:

    ReadOnlyCollection<IWebElement> cells = driver.findElements(By.XPath("//tr[@id='row']//td"));
    foreach(IWebElement cell in cells)
    {
        if (cell.Location.X == targetX && cell.Location.Y == targetY)
        {
            cell.Text;
        } 
    }

Also, FindElement will only return the first element found that matches the criteria, FindElements must be used to store all matches.

Comments

0
captcha = driver.find_element(by=By.XPATH, value=captcha_xpath)
print(captcha.text)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.