3

I am really fed up from this problem and not finding any solution.

The problem is that I am trying to test a website using test automation in C#. For this I need to sign in, but the sign-in button is not actually a button, it's a span tag with property set 'role=button'.

I am using Selenium with Chrome web driver and using unit extensions to automate the test. The problem is whenever I run the test in Test Explorer the click event is performed, but the page does not navigate to next page, and nothing happens. However, when I set a break point and run the same test through main function it works fine.

I have to set the break point to perform click operation and perform login operation.

I am using a Visual Studio console application. Here is the pic of my web site html tag.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
Lion Khan
  • 41
  • 1
  • 1
  • 3

5 Answers5

1

Try to click by JavascriptExecutor.

JavascriptExecutor is an interface provided by Selenium Webdriver

WebElement element= driver.findElement(By."Your Locator"))
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

It's an java code you can modify it using reference of below link:-

Execute JavaScript using Selenium WebDriver in C#

Hope it will help you :)

Community
  • 1
  • 1
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

The problem is most likely the Click function is not loaded at the time you run the test "quick", but it is when you debug. Try load the page. Wait for 1 second. Then getElement and click it. This is normal in pages that add javascript function to elements dynamically.

Kiksen
  • 1,559
  • 1
  • 18
  • 41
0

From what I understood the click is performed before the page is fully loaded. Try using explicit wait and expected conditins

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(logInButton)).Click();

This will wait up to 10 seconds for the button to be clickable before clicking on it.

Guy
  • 46,488
  • 10
  • 44
  • 88
0

If you have Selenium.Support included in your project you can do the following

Driver.ExecuteJavaScript("arguments[0].click();", element);

ExecuteJavaScript is an extension method available in the library

Shashank Shekhar
  • 3,958
  • 2
  • 40
  • 52
-1

I fixed this issue by storing element in an IWebElement type variable and then click it.

IWebElement runButton = driverIE.FindElement(By.XPath("//*your XPath"));
runButton.Click();
Ashok
  • 1,868
  • 6
  • 36
  • 70