Is'haq
Is'haq

Reputation: 184

Click event is not working for the Button Sin Selenium

Till yesterday my code was working to click this button, but now when I am trying to use the same code, the button is just getting highlighted and not clicked. Have tried every possible way to clicking it by surfing on internet and finding solutions but nothing works.

enter image description here

                               IWebElement ele = river.FindElement(By.Id("btnToTranslate"));
                               IJavaScriptExecutor executors = (IJavaScriptExecutor)driver;                                                    executors.ExecuteScript("arguments[0].scrollIntoView()", ele);
                               ele.Click();
                               ele.SendKeys(Keys.Enter);//even tried sending enter button but nothing happens.

the element what I am trying to fetch is

enter image description here

Thank you in advance.

Upvotes: 1

Views: 445

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

I think you need to wait using explicit wait and then use Actions class to click :

var element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.Xpath("//span[text()='Translate']")))
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Build().Perform();

Upvotes: 1

Related Questions