Reputation: 13
I am trying to locate element which may have different ID at times. Here is the example :
id = 'greenbay_packers"
id = "Sf_49ers"
Now, is there a way do to some kind of OR operation in find_element method? so that I can use same element locator for test steps?
Also if this is not possible, is there a way to write fail safe routine that try to locate using find_element(:id,'greenbay_packaers"
) but if fails try find_element(:id,'sf_49ers
"). And only fail test if above 2 are not found.
thanks
Upvotes: 0
Views: 196
Reputation: 16201
It is possible with or
//*[(@id='test1') or (@id='test2')]
For second part,
I would suggest you to try try..catch..finally
since you have only two conditions to match
try
{
Driver.FindElement(By.Id("ID1"));
}
catch (NoSuchElementException ex)
{
Driver.FindElement(By.Id("ID1"));
}
finally
{
Console.WriteLine("Failed");
}
Written in C#
Upvotes: 2