非常抱歉,这个问题比较长。
更具体地说,我正在尝试点击显示在第四行的铅笔图标(编辑按钮)。
这是我尝试执行的代码:
WebElement ele = driver.findElement(By.xpath("//a[contains(@title, 'Edit Row')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
Executor1.executeScript("arguments[0].click();", ele);
我运行selenium代码后,驱动程序实际上点击了第一行(Administration | NA)的编辑按钮,而不是第四行。我发现不仅是第一行,其他行也有相同的HTML代码,唯一的区别是铅笔/编辑按钮被隐藏,因为我不是创建该行值的人。
我也尝试了以下代码:
driver.findElement(By.xpath("//a[contains(@title, 'Edit Row')]")).click();
我随后收到了错误提示。
element is not currently visible and so may not be interacted with
似乎驱动程序仍在查看第一行中隐藏的编辑按钮,而不是第四行中明显可见的按钮。
有没有办法根据值而不是行号点击编辑按钮?原因是将来我输入的测试值可能不会出现在第四行,而是在第一行或第十行等其他行。
最后但并非最不重要的,我的Safari似乎无法运行JS Executor代码,每次尝试后都会返回以下错误:
org.openqa.selenium.WebDriverException: 'undefined' is not a function (WARNING: The server did not provide any stacktrace information)
有人可以帮我解释一下吗?
谢谢!