2015-01-12 110 views
-1

下面是接受/拒绝按钮的html细节。无法通过selenium webdriver点击updatepanel中的按钮java

<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

您是否收到任何异常? – xyz

+0

是的,因为司机无法找到按钮。 所以我让驱动程序向下滚动页面,因为按钮是躺在页面的底部。 –

回答

0

你看过相关的问题,例如this one

这表明,使用类似: driver.findElement(By.xpath("//div/button[text()='Accept' and @class='btn-primary']")).click();

+0

驱动程序无法找到该元素。 –

0

可以使用任下面的代码点击 '接受' 按钮:

driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[1]")).click(); 

OR

driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[.='Accept']")).click(); 

而且,您可以使用要么以下代码点击 '拒绝' 按钮:

driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[2]")).click(); 

OR

driver.findElement(By.xpath("//div[@id='ContentPlaceHolder1_EmployeeProfile_divAction']/button[.='Reject']")).click(); 
+0

获取此错误:org.openqa.selenium.WebDriverException:未知错误:元素在点(82,857)处不可单击。其他元素将获得点击 –

+0

您尝试了哪个选项? – Subh

+0

接受的两个选项。尽管我的测试用例成功执行,但“接受”按钮没有被selenium驱动程序点击。 –

0

你可以试试下面的方法

driver.findElement(By.xpath("//button[contains(.,'Accept')]".submit(); 

driver.findElement(By.xpath("//button[contains(.,'Reject')]".submit(); 
+0

驱动程序没有点击按钮。刚通过线路并执行测试用例。 –

+0

请发布您的完整代码,以便我们知道问题出现在哪里 – VVV

-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‌​(); 
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(); 

或可能是以下代码: -

// 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(); 
相关问题