首页 > 解决方案 > Click 事件不适用于 Button Sin Selenium

问题描述

直到昨天,我的代码一直在单击此按钮,但现在当我尝试使用相同的代码时,该按钮只是突出显示而没有被单击。已经尝试了所有可能的方法来通过在互联网上冲浪并找到解决方案来点击它,但没有任何效果。

在此处输入图像描述

                               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.

我要获取的元素是

在此处输入图像描述

先感谢您。

标签: c#selenium

解决方案


我认为您需要使用显式等待等待,然后使用 Actions 类单击:

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();

推荐阅读