由于另一个元素重叠,因此无法单击必需元素,也尝试了滚动代码

时间:2016-08-09 07:11:46

标签: selenium

测试案例 需要选中复选框,并且需要选择相应的下拉值。

问题: 无法单击元素,因为另一个元素在所需元素上重叠。错误是

  

元素不可点击(898.9500122070312,16.5)。其他   元素将收到点击:
  命令持续时间或超时:76毫秒

public class ProfileCreation {

public static WebDriver driver ;

public static void main(String[] args) {

    WebDriver driver = new FirefoxDriver();

    JavascriptExecutor jse = (JavascriptExecutor)driver;

    String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());

    System.out.println("Profile Name ===>"+ timeStamp );

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    driver.get("http://suite.simplify360.com");

    driver.findElement(By.cssSelector(".form-login.first-input")).sendKeys("alexxm360@gmail.com");

    driver.findElement(By.id("login_password")).sendKeys("Simplify360@");

    driver.findElement(By.id("rp")).click();

    driver.findElement(By.linkText("Listen")).click();

    driver.findElement(By.xpath("//input[contains(@onclick,'createNewProfile();')]")).click();

    driver.findElement(By.xpath("//input[@id='dashboardName']")).sendKeys(timeStamp);

    System.out.println("Profile Name ===>"+ timeStamp );

    WebElement slider = driver.findElement(By.xpath("//*[@id='slider-range-max']/a[2]"));

    Actions move = new Actions(driver);

    Action action = (Action) move.dragAndDropBy(slider, 30, 0).build();

    action.perform();

    WebElement permissionDropDown = driver.findElement(By.id("actionPerm"));

    Select oselect = new Select(permissionDropDown);

    List <WebElement> elementCount = oselect.getOptions();

    //      System.out.println("Count of Options"+elementCount.size());

    int iSize = elementCount.size();

    // For priting the values in permission

    /*for(int i =0; i<iSize ; i++){

        String sValue = elementCount.get(i).getText();

        System.out.println("permissoin Values"+sValue);

        }*/

    oselect.selectByVisibleText("OPEN");

    oselect.selectByVisibleText("WARN");

    oselect.selectByVisibleText("BLOCK");

    if (driver.findElements(By.cssSelector("a.cb-enable.selected")).size() > 0 ) {

        driver.findElement(By.xpath("//span[contains(.,'Off')]")).click();

    } else {

        driver.findElement(By.xpath("//span[contains(.,'On')]")).click();

    }

    if(driver.findElements(By.id("reassignPeriodMins")).size() > 0){

        WebElement caseAssociateMin = driver.findElement(By.id("reassignPeriodMins"));

        Select timeSelect = new Select(caseAssociateMin);

        WebElement firstSelectedOption = timeSelect.getFirstSelectedOption();

        System.out.println("Default Selected Time"+firstSelectedOption.getText());

        timeSelect.selectByVisibleText("45");

    }

    if(driver.findElements(By.id("replySetting")).size() > 0){

        WebElement replySetting = driver.findElement(By.id("replySetting"));

        Select replyType = new Select(replySetting);

        WebElement firstSelectedOption = replyType.getFirstSelectedOption();

        System.out.println("Default Selected Time"+firstSelectedOption.getText());

        replyType.selectByVisibleText("REPLY");

        replyType.selectByVisibleText("REPLYALL");

    }

    System.out.println( "checkboxes" + driver.findElements(By.className("shareCheck")).size());

    int sizeOfUsers = driver.findElements(By.className("shareCheck")).size();


    for (int i = 1; i <= sizeOfUsers; i++) {

        boolean fname = driver.findElement(By.xpath("//*[@id='basketusers']/tbody/tr["+ i +"]/td[3]/input")).isEnabled();

        if (fname == false){

            String disblaedEmailID = driver.findElement(By.xpath("//*[@id='basketusers']/tbody/tr["+ i +"]/td[2]/div")).getText();

            String loginEmailId = "nagarjun.reddy@in-rev.com";

            if( disblaedEmailID == loginEmailId){

                System.err.println("Check Box is disabled ====>"+disblaedEmailID);

            }

            System.err.println("i value==>"+ i);

            i++;

            System.err.println("selected email id will be =="+ driver.findElement(By.xpath(".//*[@id='basketusers']/tbody/tr["+i+"]/td[2]/div")).getText() );

            //ISSUE IS HERE. CANNOT MOVE TO THE REQUIRED ELEMENT 

            jse.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.xpath(".//*[@id='basketusers']/tbody/tr["+i+"]/td[2]/div")));

            driver.findElement(By.xpath("//*[@id='basketusers']/tbody/tr["+ i +"]/td[3]/input")).click();

            Select roleSelect = new Select(driver.findElement(By.xpath(".//*[@id='basketusers']/tbody/tr["+i+"]/td[4]/select")));

            System.err.println("First selected role ====>"+ roleSelect.getFirstSelectedOption().getText());

            roleSelect.selectByVisibleText("PROFILE AGENT");

            System.err.println("Changed role ====>"+ roleSelect.getFirstSelectedOption().getText());

        }

        //          System.err.println(  driver.findElement(By.xpath("//*[@id='basketusers']/tbody/tr["+ i +"]/td[3]/input")));

    }

    //      driver.findElement(By.xpath("//input[@value='Next']")).click();

}

}

1 个答案:

答案 0 :(得分:0)

尝试添加这样的向上滚动。

jse.executeScript("window.scrollBy(0,-250)", "");

这只会让chekbox不会隐藏eunder navbar。 我在当地尝试过它。