元素在标签内,但尝试了很多方法都无法点击它。wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='Login to Register']"))).click();和WebElement element = driver.findElement(By.xpath("//input[@value='Login to Register']"));JavascriptExecutor jsEx= (JavascriptExecutor)driver;jsEx.executeScript("arguments[0].click();", element);这是 html:<div id="requestRegistrationWidget"> <a id="requestLocationLogin" href="/user/login?destination=%2Fsearch%2Flocations%2Fwidget%3Fparam1%3D006046-0619_1565278200_11000000%26param2%3D3" class="use-ajax login-popup-form" data-dialog-type="modal"> <input class="btn btn-primary" style="width: 100% !important;" type="button" value="Login to Register"></input> </a> <!-- registerSession == 3 and registerAnyActiveSession == 1 case (2) --> </div>
3 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
你能试试下面的代码吗?
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("requestLocationLogin"))).click();
慕村9548890
TA贡献1884条经验 获得超4个赞
我想你在 chrome 上遇到了这个问题。试试这个,它对我有用。
element.sendKeys(Keys.RETURN);
它只是点击元素上的“输入”按钮。
达令说
TA贡献1821条经验 获得超6个赞
要click()
在带有文本的元素上登录以注册,因为该元素是支持AJAX的元素,您必须为此引入WebDriverWaitelementToBeClickable()
,并且您可以使用以下任一定位器策略:
cssSelector
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.use-ajax.login-popup-form#requestLocationLogin>input.btn.btn-primary[value='Login to Register']"))).click();
xpath
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='use-ajax login-popup-form' and @id='requestLocationLogin']/input[@class='btn btn-primary' and @value='Login to Register']"))).click();
添加回答
举报
0/150
提交
取消