无法单击selenium webdriver中的“按钮”(使用Java)

时间:2017-11-01 07:52:11

标签: java selenium-webdriver

这是我想要找到href按钮的代码:

<a class="btn grey-edit" data-original-title="Login" data-placement="top" 
data-toggle="tooltip" href="/users/userlogin/3">
<i class="fa fa-sign-in" aria-hidden="true"></i>

我正在使用以下xpath,但它不起作用:

driver.findElement(By.xpath("/html/body/div/div[2]/form/div[4]/div/button")).click();

this the image

2 个答案:

答案 0 :(得分:0)

根据您提供的CREATE OR REPLACE TYPE VC_MNumber AS OBJECT ( idno NUMBER, MEMBER FUNCTION dimension RETURN NUMBER, MEMBER FUNCTION typeName RETURN VARCHAR2 ) NOT INSTANTIABLE NOT FINAL; / --DROP TYPE VC_MINTEGER; CREATE OR REPLACE TYPE VC_MInteger UNDER VC_MNumber ( OVERRIDING MEMBER FUNCTION dimension RETURN NUMBER, OVERRIDING MEMBER FUNCTION typeName RETURN VARCHAR2 ); / CREATE OR REPLACE TYPE VC_MReal UNDER VC_MNumber ( YDCCoeff NUMBER, CbDCCoeff NUMBER, CrDCCoeff NUMBER, OVERRIDING MEMBER FUNCTION Dimension --<--Overriding function should have same name RETURN NUMBER, OVERRIDING MEMBER FUNCTION typeName RETURN VARCHAR2 ) FINAL; / CREATE OR REPLACE TYPE BODY VC_MReal AS OVERRIDING MEMBER FUNCTION Dimension RETURN NUMBER IS var_dimension NUMBER := 10; BEGIN RETURN var_dimension; END; OVERRIDING MEMBER FUNCTION typeName --<-- You declared in Object type as `overriding` function and using it as `Member function` alone. RETURN VARCHAR2 IS var_typeName VARCHAR2 (400) := 'VC_MREAL'; BEGIN RETURN var_typeName; END; END; / HTML 属性位于 href 标记内。因此,我们将构建一个唯一的逻辑 <a> 来定位 xpath 并调用 WebElement 方法作为如下:

click()

OR

driver.findElement(By.xpath("//a[@class='btn grey-edit' and @data-original-title='Login']")).click();

答案 1 :(得分:0)

WebElement btnElem= driver.findElement(By.xpath("//a[@class='btn grey-edit' and @href='/users/userlogin/3']"));

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", btnElem);

您也可以将JavaScriptExecutor用于相同的

    jQuery(document).ready(function(){

     jQuery(document).on('click','.ladda-button',function(){
          oniter();
    });

 });
function oniter(){

    if (jQuery(".valid").find(".active").length>=1) {
        // alert(123);
    }
    else {
      jQuery('.removeval').remove();
        jQuery(".validation_text").append("<font class='removeval'>Please Select a Day</font>");
    }
    jQuery(".valid").on ('change',function(){
      jQuery(".validation_text").remove();
    });
  }