下面提到的是接受/拒绝按钮的html详细信息。
<div id="ContentPlaceHolder1_EmployeeProfile_divAction" class="btn-row btn-accept-recet" style="display:block;">
<button onclick="__doPostBack('ctl00$ContentPlaceHolder1$EmployeeProfile$btnAccept','')" id="ContentPlaceHolder1_EmployeeProfile_btnAccept" class="btn pull-left btn-primary" type="button">
<i class="fa fa-angle-right"></i>Accept
</button>
<button onclick="__doPostBack('ctl00$ContentPlaceHolder1$EmployeeProfile$btnReject','')" id="ContentPlaceHolder1_EmployeeProfile_btnReject" class="btn pull-left btn-primary" type="button">
<i class="fa fa-angle-right"></i>Reject
</button>
</div>
我想点击更新面板中的接受或拒绝按钮。我尝试过使用动作:
WebElement element = driver.findElement(By.id("ContentPlaceHolder1_EmployeeProfile_btnAccept"));
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
答案 0 :(得分:1)
在点击所需按钮之前,请尝试使用以下内容: -
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
让我知道这是否有效......很乐意帮助.....
另外,尝试使用xpath来定位元素....在你的情况下,xpath可以是如下: -
//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[@id='ContentPlaceHolder1_EmployeeProfile_btnAccept']
如果上述方法也不起作用,请尝试使用以下代码: -
var btnAccept = GetElementWaitVisibleThrow(By.Id("<<ELEMENT HTMLID>>"));
Actions action = new Actions(driver);
action.MoveByOffset(btnAccept.Location.X + 5, btnAccept.Location.Y + 5).Click().Perform();
OR可能是以下代码: -
// Find an element and define it
WebElement elementToClick = driver.findElement(By.xpath("some xpath"));
// Scroll the browser to the element's Y position
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().y+")");
// Click the element
elementToClick.click();
答案 1 :(得分:0)
您是否查看了this one等相关问题?
这意味着使用类似的东西:
driver.findElement(By.xpath("//div/button[text()='Accept' and @class='btn-primary']")).click();
答案 2 :(得分:0)
您可以使用以下任一代码点击“接受”按钮:
driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[1]")).click();
或
driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[.='Accept']")).click();
并且,您可以使用以下任一代码点击“拒绝”按钮:
driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[2]")).click();
或强>
driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[.='Reject']")).click();
答案 3 :(得分:0)
您可以尝试以下方法
driver.findElement(By.xpath("//button[contains(.,'Accept')]".submit();
driver.findElement(By.xpath("//button[contains(.,'Reject')]".submit();
答案 4 :(得分:-1)
driver.manage().window().maximize();
WebElement scroll = driver.findElement(By.id("ContentPlaceHolder1_EmployeeProfile_btnAccept"));
scroll.sendKeys(Keys.PAGE_DOWN);
driver.findElement(By.id("ContentPlaceHolder1_EmployeeProfile_btnAccept")).click();