gpt4 book ai didi

java - Xpath 选择器在 IE 中不起作用,但在 Chrome 和 Firefox 中工作正常

转载 作者:行者123 更新时间:2023-12-01 10:10:58 24 4
gpt4 key购买 nike

我正在使用以下 xpath 在 Selenium webdriver 中使用 JSExecutor 单击元素。这在 Firefox 和 Chrome 中工作正常,但在 IE 中不起作用。

有什么想法可以让这个工作成功吗?经过大量的试验和错误,我在 FF 和 chrome 中完成了这项工作,并提出了以下 XPath。

//*[contains(@class,'ui-select-choices-row') or contains(@id,'ui-select-choices-row')]//*[text()='TextofMyElementToBeclicked'

附加信息:这是 angularJS 应用程序上的 Jquery 下拉菜单。当用户单击下拉列表时,//ul 被加载,并且我使用上面的 xpath(这是//ul 的一部分)根据文本选择元素(使用 Javascript 执行器单击)。我使用JS执行器是因为selenium中的click()函数根本无法点击下拉元素。

我正在使用下面的按钮单击元素。

WebElement element = driver.findElement(By.xpath("YourNumbersXpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
enter code here

最佳答案

我成功使用 IE11 测试了您的 XPath,因此这不是与 IE 相关的问题。这很可能是一个时间问题。首先点击下拉按钮,然后等待目标元素出现,最后点击它:

WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("...");

// move the cursor to the menu Product
WebElement element = driver.findElement(By.xpath("drop down button")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("drop down item"))).click();

关于java - Xpath 选择器在 IE 中不起作用,但在 Chrome 和 Firefox 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36119324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com