Search code examples
seleniumselenium-webdriverselenium-chromedriver

How to find an item in Selenium WebDriver?


I want to find the following item using Selenium. The value of the class changes whenever there is a change. This is inside a complex page (multiple iframes, and other items loaded dynamically). The only unique id is itemid, which is dynamic value and title combination. If I click on this Action, am getting another new set of complex items. I am new to Selenium. How to do that?

HTML:

<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button">Actions&nbsp;<img src="../row.gif"></td>

<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button button-active">Actions&nbsp;<img src="../row.gif"></td>

<td itemid="xxyyy.as123" title="Actions" nowrap="" class="text-button button-hover">Actions&nbsp;<img src="../row.gif"></td>

The code I tried:

  1. Find by Xpath

    var element=driver.FindElement(By.XPath("html/body/div[id='pageContent']/iframe/#document/ht‌ml/frameset/frame[name='detailsDisplay']/#document/html/body/form[name='tableForm‌']/div[id='divToolbarContainer']/div[id='divToolbar']/div[1][class='toolbar']/tab‌​le/tbody/tr/td[title='Actions']"));
    
  2. Find by Link Text

    var element = driver.FindElement(By.LinkText("Actions"));
    

Any help would be appreciated.


Solution

  • Finally I was able to achieve it, by using the frame names.

     driver.SwitchTo().Frame("content").SwitchTo().Frame("detailsDisplay");                        
     var element = driver.FindElement(By.XPath("//*[@id=\"divToolbar\"]/div[1]/table/tbody/tr/td[1]"));
    

    Thanks everyone.