Im doing webtest using selenium Webdriver in C#. But I'm having a problem where when the browser window isn't in full size a popup will open half way outside the visible area.
The problem is that when i fire a .Click(); it doesn't do anything because the link i attempt to click is outside of the viewed area.
So how do i focus on the link to get click to work? Im currently using the following workaround but i don't think that's a nice way.
_blogPostPage.FindElement(By.XPath(_popupLogin)).SendKeys("");
_blogPostPage.FindElement(By.XPath(_popupLogin)).Click();
The sendkeys with space focuses on the link and makes Click work everytime, but isn't there a right way to do it?
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
Selenium driver object can access the elements of the parent window. In order to switch its focus from the parent to the new popup tab, we shall take the help of the switchTo(). window method and pass the window handle id of the popup as an argument to the method.
Instead of doing send key for blank value, send it for space. Thats the keyboard shortcut to select a checkbox.
Just replace the code :
_blogPostPage.FindElement(By.XPath(_popupLogin)).SendKeys("");
_blogPostPage.FindElement(By.XPath(_popupLogin)).Click();
by
_blogPostPage.FindElement(By.XPath(_popupLogin)).SendKeys(Keys.Space);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With