Here I'm using LinkedIn for the learning purpose & want to perform the action on Edit profile=> Work experience=> Add position. Here "Add position" button comes under work experience which becomes visible on hovering to that specific area. Look at my code,

driver.findElement(By.id("login email")).sendKeys("email id");

/* To scroll the page down */

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");

/* To hover mouse on required option*/

Actions hover=new Actions(driver);

/* To Edit company name */

driver.findElement(By.xpath("id('companyName-positionCompany-position-editPositionForm')")).sendKeys("testing company");

This is continued to edit work details but when I execute, it stops the page at work experience & not able to click on add position button to edit work. It gives error on "edit company" code line. Can anyone help me perform the same?

  • What error are you getting?
    – FDM
    Commented Oct 31, 2015 at 8:31
  • I got such, org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"id('companyName-positionCompany-position-editPositionForm')"}
    – Disha
    Commented Oct 31, 2015 at 9:18
  • After trials, i found that it's working by changing pixel value from, jse.executeScript("window.scrollBy(0,250)", ""); to jse.executeScript("window.scrollBy(0,500)", ""); . So now i'm worried how can i define this pixel value?? Is there any way?
    – Disha
    Commented Oct 31, 2015 at 11:17
  • Try pausing for few seconds after you move the mouse cursor over the element and before you click it.
    – Nitesh
    Commented Nov 2, 2015 at 8:40
  • To avoid hard coding the pixel values you could create a for while to scroll piece by piece and put your test cases into a try catch block. Boolean Performed = false; while(Performed == false){ try{ //whatever you want it to do Performed = true; }catch(NoSuchElementException e){ se.executeScript("window.scrollBy(0,50)", "");} //or whatever value you want } This would try to perform the specified action and scroll down by 50 pixels if it failed, so after 10 iteration in your case it would go through.
    – Daniel
    Commented Jun 30, 2016 at 12:53

2 Answers 2


I would suggest to use perform() function on the main menu link to hold the menu list till the time Selenium identifies the required sub-menu link and then click on it. I have modified your code (just added a perform() function on line 2).Hope this helps.

Actions hover=new Actions(driver);
  • I tried with perform() already but couldn't help me out! See my last comment under the question.
    – Disha
    Commented Nov 2, 2015 at 6:49
  • Since you are clicking the same element after moving to it. I have added click and perform method on the same line. Actions hover=new Actions(driver); hover.moveToElement(driver.findElement(By.xpath("id('background-experience')/div[1]/div/button[1]"))).click().perform(); Thread.sleep(5000); Do you mind trying this ? Commented Nov 3, 2015 at 22:59
  • I tried with your given code.Thanks for your response, but unfortunately I got the same error. I thought its unable to scroll & locate the element so I've modified pixel value from jse.executeScript("window.scrollBy(0,250)", ""); to jse.executeScript("window.scrollBy(0,600)", ""); And surprisingly its working!
    – Disha
    Commented Nov 5, 2015 at 7:46

Simple way & working solution, When you want to take action on Hidden element

  1. First of all we know that element should be visible

    hidden_element.send_keys ""
  2. Once element get visible using selenium we can easily take any action


I hope code snippet will help you! Try it

  • How does sendKeys has anything to do with visibility?
    – FDM
    Commented Oct 13, 2016 at 8:36
  • Probably it forces a scroll and on-focus Commented Mar 26, 2017 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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