0

I am using Selenium Chrome driver/ C# to select buttons on a website. They don't have id tags only the class tags. How do I select these types of button.

Usually I would do something like this if I have the Id.

 var _SignInButton = driver.FindElement(By.Id("SignInButton"));
_SignInButton.Click();

Example of one these buttons class name is

class="button-71444407 blue-3811567280"
PROG_MJ
  • 13
  • 2
  • Possible duplicate of [Compound class names are not supported. Consider searching for one class name and filtering the results](http://stackoverflow.com/questions/20361643/compound-class-names-are-not-supported-consider-searching-for-one-class-name-an) – JeffC Apr 22 '17 at 21:17
  • Welcome to Stack Overflow! Please read [ask] and [How much research effort is expected?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) Please provide the code you have tried and the execution result including any error messages, etc. – JeffC Apr 22 '17 at 21:18

2 Answers2

1
var _SignInButton =
  driver.FindElement(By.CssSelector(".button-71444407.blue-3811567280"));

See also Selenium Documentation http://www.seleniumhq.org/docs/

EDIT:

driver.FindElement(By.CssSelector("button.button-71444407.blue-3811567280"));

Should find all buttons with class value button-71444407 and blue-3811567280

driver.FindElement(By.XPath("//button[@class='button-71444407 blue-3811567280']"));

Should find exactly that button and all other buttons with class value button-71444407 blue-3811567280 (order of values matters)

driver.FindElement(
  By.XPath("//button[contains(@class, 'button-71444407 blue-3811567280')]"));

Should find exactly that button and all other buttons with class value containing button-71444407 blue-3811567280 (order of values matters)

  • I think the answer is correct. it is just not working for me, in this particular application. here is the button html: – PROG_MJ Apr 22 '17 at 20:10
0

Select exactly same with the class name:

ChromeDriver.FindElement(By.XPath("//button[@class = 'button-71444407 blue-3811567280']"));

Everything name that contains in:

ChromeDriver.FindElement(.XPath("//button[contains(@class, 'button-71444407 blue-3811567280')]"));
Haryono
  • 2,184
  • 1
  • 21
  • 14