0

when going to the site when you go to the site, the button "Continue" can have 2 options: class="button" or class="btn". How to do a search at once for 2 classes in 1 FindElement. I do not know how it should look, but like so (schematically)

IWebElement element = driver.FindElement(By.ClassName("button" or "btn"));

Or easier to use if else?

IWebElement element18 = driver.FindElement(By.XPath("//div[contains(@class, 'button') or contains(@class, 'btn')]"));

Not work.

Thank you for attention

2 Answers2

2

If XPath doesn't work you can write something like this:

public IWebElement GetElements(params By[] searchBy)
{
    var list = new List<IWebElement>();
    foreach (var by in searchBy)
    {
        list.AddRange(driver.FindElements(by));              
    }
    return list.Count == 1 ? list[0] : null;
}
unickq
  • 1,497
  • 12
  • 18
0

This is really simple using a CSS selector, ".button, .btn", or if you want to be more specific, "div.button, div.btn". The comma equates to an OR operator.

JeffC
  • 22,180
  • 5
  • 32
  • 55