Kishan Rathod
Kishan Rathod

Reputation: 83

Not able To click in selenium browser with C#

Button type is Input.

<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit btn solid">

I want to click this Button using code, try to click on Button By ClassName.

My code is as per below but not get any success.

string url1 = "myUrl";
IWebDriver driver = new ChromeDriver(Application.StartupPath);
driver.Navigate().GoToUrl(url1);    
driver.FindElement(By.ClassName("wpcf7-form-control .wpcf7-submit btn solid")).Click();

This throws the following error :

Compound class names not allowed. Cannot have whitespace in class name. Use CSS selectors instead. and not use single class because there is a other class with same name.

Upvotes: 0

Views: 644

Answers (2)

Purvesh Patel
Purvesh Patel

Reputation: 86

driver.FindElement(By.XPath("//input[@type='submit']")).Click();

Upvotes: 1

Martin B
Martin B

Reputation: 1

I would try to avoid using XPath, Instead I would add an Id to your input. The reason being XPath is more likely to be changed over time than Id. Also if you add another element with the same HTML, selenium will not be able to differentiate between them and will always select the first element. Using Id also makes your code more readable. You can try this:

<input type="submit" value="Send" Id="YourButtonId" class="wpcf7-form-control wpcf7-submit btn solid">

And

 driver.FindElement(By.Id("YourButtonId")).Click();

Upvotes: 0

Related Questions