-1
  • Environment : IE11
  • Webdriver/Selenium version : 3.141.59
  • Language : java

Selenium code:

driver.findElementByXPath("//span[contains(text(),'Logout')]").click();**

HTML code :

<span class="v-menubar-menuitem-caption">Logout </span>
8
  • What is the error you get?
    – Patrick
    Jun 21 '19 at 5:36
  • @Patrick Getting the following Exception Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException:
    – Abhiram
    Jun 21 '19 at 5:58
  • @Abhiram can you share your complete menubar HTML code and aslo please share your complete selenium code(method). Jun 24 '19 at 13:40
  • Because the exception you are getting is of Action class Jun 24 '19 at 13:41
  • @UpkarSingh shouldn't we use Actions class for this user action ? when i use normal click nothing happens
    – Abhiram
    Jun 26 '19 at 4:17
0

Have a small correction in your Selenium code:

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

2
  • Getting the following Exception while using above code Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Cannot click on element Build info: version: '3.141.59', java.version: '1.8.0_74'
    – Abhiram
    Jun 21 '19 at 5:47
  • I have verified that element is displayed and clickable
    – Abhiram
    Jun 21 '19 at 5:59
0
  1. It might be the case the element is not present yet by the time you're trying to click it. Consider using WebDriverWait in order to ensure that the element is really there and can be clicked, suggested code amendment:

    WebDriverWait wait = new WebDriverWait(driver,10);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(),'Logout')]"))).click();
    
  2. It might be the case the element doesn't fit at the screen, try maximizing the browser window so more elements could be displayed:

    driver.manage().window().maximize();
    
  3. In the majority of cases you should not be clicking the span, I would rather expect an input or a link

1
  • The button is built using span class. added the following code and check .But still doesnt work same exception is thrown Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Cannot click on element
    – Abhiram
    Jun 21 '19 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.