MoveToElement is not working

Not reproducible Issue #12233863

Details

Author
Anda C.
Created
Jun 4, 2017
Privacy
This issue is public.
Found in
  • Microsoft Edge
Found in build #
14.14393
Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

I have the code:

package Test.YhaooMailEdgeRemotely;

import static org.junit.Assert.*;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import com.gargoylesoftware.htmlunit.javascript.host.Location;

public class ComposeEmailYahoo {

private static final String USERNAME = "test13086";
private static final String AUTOMATE_KEY = "95oQezs5cV45sA287xYe";
private RemoteWebDriver driver;
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY
        + "@hub-cloud.browserstack.com/wd/hub";

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
    try {
        if (driver != null)
            driver.quit();
        else {
            DesiredCapabilities capabilities = DesiredCapabilities.edge();

            capabilities.setCapability(
                    CapabilityType.SUPPORTS_APPLICATION_CACHE, false);

            capabilities.setCapability("browserstack.user", USERNAME);
            capabilities.setCapability("browserstack.key", AUTOMATE_KEY);
            capabilities.setCapability("browserstack.debug", true);
            LoggingPreferences logPrefs = new LoggingPreferences();
            logPrefs.enable(LogType.BROWSER, Level.ALL);
            logPrefs.enable(LogType.CLIENT, Level.ALL);
            logPrefs.enable(LogType.DRIVER, Level.ALL);
            logPrefs.enable(LogType.SERVER, Level.ALL);
            logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS,
                    logPrefs);

            capabilities.setCapability("browser", "Edge");
            capabilities.setCapability("acceptSslCerts", true);
            capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY,
                    "eager");

            capabilities.setCapability("os", "Windows");
            capabilities.setCapability("os_version", "10");

            driver = new RemoteWebDriver(new java.net.URL(URL),
                    capabilities);
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

            driver.manage().window().maximize();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

@After
public void tearDown() throws Exception {
    driver.quit();
}

@Test
public void DeleteTrashEmails() throws Exception {
    try {

        Integer pozSpam = 0;
        Integer pozTrash = 0;
        Integer pozHelp = 0;
        Integer pozCompose = 0;
        Integer pozNewFolder = 0;
        driver.get("https://mail.yahoo.com");
        driver.manage().window().maximize();
        WebElement usernameElem = driver.findElement(By
                .id("login-username"));
        usernameElem.sendKeys("andadeacu@yahoo.com");

        WebElement Next = this.driver.findElement(By.id("login-signin"));
        Next.click();

        WebElement passwordElem = this.driver.findElement(By
                .name("password"));

        boolean selected = passwordElem.isSelected();

        Actions builder = new Actions(this.driver);

        builder.perform();
        CharSequence password = "";
        passwordElem.sendKeys(password);

        WebElement login = driver.findElement(By.id("login-signin"));

        login.click();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        // <label class="compose-label"
        // id="yui_3_16_0_ym19_1_1496344582966_3534"
        // for="from-field">From</label>
        // <div class="composeshim hidden"></div>
        driver.switchTo().activeElement();

        WebElement btnCompose = driver
                .findElement(By
                        .xpath("//div[@id = 'shellnavigation']/div/ul/li[@id = 'Compose']/button[@class='btn btn-compose']"));

        System.out.println(btnCompose.getText() + " class: "
                + btnCompose.getAttribute("class"));
        
        // get location
        Point pCompose = btnCompose.getLocation();
        // move to Imagine Help
        ((JavascriptExecutor) driver).executeScript("window.scrollTo("
                + pCompose.x + "," + pCompose.y + ");");

        Actions builder_1 = new Actions(this.driver);

        //builder_1.
        builder_1.moveToElement(btnCompose);
        
        builder_1.sendKeys("");
        
        builder_1.build().perform();

        //btnCompose.;
        

        System.out.println(btnCompose.isSelected());

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

        driver.switchTo().activeElement();

        // System.out.println(driver.getCurrentUrl());

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

}

It is very frustrating because MoveToElement is not working. nad in my console it is not an exception.

My console is :

Jun 04, 2017 9:30:48 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel’s Law holds true on the remote end
Jun 04, 2017 9:30:53 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Compose class: btn btn-compose
false

To run my test you can have user of Yahoo Email and an user on BrowserStack.
The test case is successful and the ‘Compose’ button is found but it haven’t focus.

I don’t understand what is the reason.

Thanks a lot,

Attachments

0 attachments

    Comments and activity

    • I modified my code so:

      By btnBy = By
      .xpath("//div[@id = ‘shellnavigation’]/div/ul/li[@id = ‘Compose’]/button[@class=’btn btn-compose’]");
      WebDriverWait wait = new WebDriverWait(driver, 10);
      wait.until(ExpectedConditions.presenceOfElementLocated(btnBy));

              WebElement btnCompose = driver
                      .findElement(By
                              .xpath("//div[@id = 'shellnavigation']/div/ul/li[@id = 'Compose']/button[@class='btn btn-compose']"));
      
              System.out.println(btnCompose.getText() + " class: "
                      + btnCompose.getAttribute("class"));
              btnCompose.click();
      

      But I have another problem:

      I don’t know how to navigate to one frame:

      Using developer tools how to know in which frame am I?

      Thanks a lot.

    • Microsoft Edge Team

      Changed Assigned To to “Steven K.”

    • Hi Anda,

      Glad you found the explicit wait.  WebDriver waits seem to help avoid automation failures.

      In regards to the switching frames/windows, you should take a look at the switchTo() method.

      http://www.seleniumhq.org/docs/03_webdriver.jsp#moving-between-windows-and-frames

      Also, useful is how to handle pop-ups and alerts.

      http://www.seleniumhq.org/docs/02_selenium_ide.jsp#alerts-popups-and-multiple-windows

      Thank you for the support,

      The MS Edge Team

    • Forgot to answer your other question, even though this site mainly to receive reports for Edge browser defects.  Just a developer helping another. :-)

      // Get and store both window handles in an array

      Set<String

      AllWindowHandles = driver
      .getWindowHandles();
      for
      (String
      value : AllWindowHandles){
      System.out
      .println(value);
      }

      Steve

    • To get the current window:

      driver
      .getWindowHandle();

    • Ok, thanks for your replay.

    • Hi Steve,

      I want to get iframes or frames, not windows.
      Edge driver haven’t no method to get all frames.

    • Do you mean they are not working?

      Switch to frame has been supported since release 10586.

      https://docs.microsoft.com/en-us/microsoft-edge/webdriver-commands

      Here is an example:

      http://learn-automation.com/handle-frames-in-selenium/

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11

       
      try

      {

       

      driver
      .
      switchTo
      (
      )
      .
      frame
      (
      indexnumber
      )
      ;

       
          
       }

      catch

      (
      NoSuchFrameException

      e
      )

          
      {
                  
       

      System
      .
      out
      .
      println
      (
      e
      .
      getMessage
      (
      )
      )
      ;
           
       
           
      }

    • Anda,

      I plan to move this bug report to resolved.  If you find that a feature is not working and is listed as being supported, please let us know by submitting a new bug report.

      Appreciate the discussion and the support for Edge,

      cheers,

      Steve

    • Microsoft Edge Team

      Changed Status to “Confirmed”

      Changed Status from “Confirmed”

      Changed Status to “Not reproducible”

    You need to sign in to your Microsoft account to add a comment.

    Sign in