I am having an issue with Selenium WebDriver. I try to click on a link that is outside the window page (you'd need to scroll up to see it). My current code is fairly standard:
menuItem = driver.findElement(By.id("MTP"));
menuItem.click();
// I also tried menuItem.sendKeys(Keys.RETURN);
I know I could scroll up, and it would work in this case. But in a case where you have a long list of items, you don't necessarily know how far you have to scroll down.
Is there any way to click on a link that is not on the visible part of the page (but that would be visible if you scroll)?
As a side note, I'm using Firefox, but I am planning to use IE7/8/9 and Chrome as well.
Any help would be greatly appreciated.
Edit: I'm afraid I can't give the source code, as the company I work for doesn't allow it, but I can give the code of the link I want to click on:
<div class="submenu">
<div id="MTP">Link title</div>
</div>
The exact same code works when the link is visible, only when it is not does it not work.
Edit2: Actually, oddly enough, it doesn't raise any exception and just goes to the next instruction. So basically, what happens is:
menuItem = driver.findElement(By.id("MTP")); // no exception
menuItem.click(); // no exception
//... some code ensuring we got to the next page: timeout reached
driver.findElement(By.id("smLH")).click(); // NoSuchElementException, as we're on the wrong page.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…