我试图点击“搜索”按钮,但没有成功。我也尝试过搜索 iframe 但没有 iframe。
这是我的“搜索”按钮 html 标签:
<input type="submit" value="search">
这是我用来单击“搜索”按钮的 xpath:
driver.findElement(By.xpath("//*[@id='mainDiv']/table/tbody/tr/td/div[3]/blockquote/fieldset/input[1]")).click();
我尝试过以下方法:
new Actions(driver).moveToElement("//*[@id='mainDiv']/table/tbody/tr/td/div[3]/blockquote/fieldset/input[1]").perform();
JavascriptExecutor jse = (JavsscriptExecutor)driver; jse.executeScript("document.getElementById(//*[@id='mainDiv']/table/tbody/tr/td/div[3]/blockquote/fieldset/input[1]").focus().click();");
new WebDriverEait(driver, 10).until(ExpectedConditions.ElementToBeClickable(By.cssSelector(Inpout.submit[value='search']"))).click();
driver.findElement(By.cssSelector(".submit[value='search']")).click();
上述方法应该能够单击“搜索”按钮。
但是,我遇到异常:无法使用 cssSelector 或 xpath 或 id 找到元素
最佳答案
为什么使用绝对xpath而不是尝试相对xpath,如下所示
driver.findElement(By.xpath("//*[@type='submit'])).click();
关于java - 无法单击 "Search"按钮 Selenium Web 驱动程序 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57549468/