我正在尝试自动控制图像元素“ svg”,其中包含12个可选部分(带有“ path”标签)。
在我所有的电子角度应用程序中,我必须将js动作与Selenium一起使用才能单击按钮或其他UI元素。 Selenium Click函数或Actions类不适用于我。
因此,当我尝试单击“ svg”元素之一时:
IWebElement patientIllustration = electron.driver.FindElement(By.Id("patientIllustration"));
IWebElement shadow = (IWebElement)jse.ExecuteScript("return arguments[0].shadowRoot", patientIllustration);
IWebElement body = shadow.FindElement(By.Id("adult_vascular"));
IReadOnlyCollection<IWebElement> parts = body.FindElements(By.TagName("path"));
IWebElement bodyPart = parts.ElementAt(0);
jse.ExecuteScript("arguments[0].scrollIntoView(true);", bodyPart);
jse.ExecuteScript("arguments[0].click();", bodyPart);
我收到以下错误:
OpenQA.Selenium.WebDriverException:'未知错误:arguments [0] .click不是函数 (会话信息:content shell =) (驱动程序信息:chromedriver = 2.36(7361dbe5ac927be4276ec7da1d3548c4f22343a0),platform = Windows NT 10.0.14393 x86_64)'
我也尝试使用Click()方法和Actions类单击bodyPart元素。但却什么也没做这两种可能性不适用于我的应用程序中的任何元素。
还有其他想法可以尝试吗?
答案 0 :(得分:0)
代替此
jse.ExecuteScript("arguments[0].scrollIntoView()", bodyPart);
你能尝试这个吗?
jse.ExecuteScript("arguments[0].scrollIntoView(true);", bodyPart);
答案 1 :(得分:0)
此错误消息...
OpenQA.Selenium.WebDriverException: 'unknown error: arguments[0].click is not a function
(Session info: content shell=)
(Driver info: chromedriver=2.36
(7361dbe5ac927be4276ec7da1d3548c4f22343a0),platform=Windows NT 10.0.14393 x86_64)
...表示 ChromeDriver 无法与 WebBrowser 进行通信,即 Chrome浏览器会话。
您的主要问题是所使用的二进制版本之间的不兼容性:
支持 Chrome v63-65
支持 Chrome 73版
因此 ChromeDriver v2.36 与 Chrome浏览器v73.0
之间存在明显的不匹配@Test
。