0

for locating the element by name I did:

text_field = driver.find_element_by_name('panelHeader')

the problem was that ... there are 3 panel with same name 'panelHeader' and depending upon action on particular webpage, the required panel (out of 3) get visible. So whenever i try to locate element by name, always it tries to find the first panelHeader. So cant i do something like find element by name such that the name i denote is for the visible panel.

Am I clear?

Ajay
  • 4,134
  • 3
  • 20
  • 19

2 Answers2

1

Try to locate it with jQuery. This is how it can be done in JAVA: Selecting and Identifying element with JQuery to use it in Selenium 2 Java API. Where your jQuerySelector will be look something like that:

String jQuerySelector = "'$("*[name='panelHeader'].filter(':visible')")'";
Community
  • 1
  • 1
Aleh Douhi
  • 1,958
  • 1
  • 14
  • 13
0

I use C# but I imagine this is possible in python too. You could get all the elements by name and then check each elements 'displayed' value. Eg. (in C#, sorry! :P)

ReadOnlyCollection<IWebElement> things = driver.FindElements(By.Name("panelHeader"));
foreach(IWebElement thing in things)
{
    if (thing.displayed)
    {
        //use thing here! :)
    }
} 
Nashibukasan
  • 2,028
  • 23
  • 37