技术改变人生!

selenium 不支持IE条件下滚动条滚动,不支持视野之外元素操作,解决办法

上一篇 / 下一篇  2013-02-08 13:48:11 / 个人分类:selenium

在项目中我遇到这个这样问题,需要验证6个checkbox,每个checkbox需要输入一组值,让后再下方显示搜索结果,因为每个checkbox被检索的值搜出的结果数量 不一样,有的检索结果值很多,直接把滚动条拉大下方了,当脚本检查下个checkBox的时候,selenium在IE环境下,不支持不可视化查找,所以就没点击到下个checkBox,导致失败,解决办法是把焦点移到到下个checxbox,这就需要移到页面滚动条,我们可以使用这个函数radioElement.SendKeys("");把焦点移到需要检测的元素上,下面为操作代码:
 
 
foreach (var radioElement in radioElements)
            {
                if (radioElement.Text == type && searchValue != null)
                {
                    string elementText = radioElement.Text;

                    radioElement.SendKeys("");
                                      radioElement.Click();
                    Log(string.Format("radio type is '{0}' ", elementText));
                    var searchInputElement = GetElement(WindowPanel, By.CssSelector(".x-form-text.x-form-field"));
                    Log(string.Format("Enter search value is '{0}' ", searchValue));
                    searchInputElement.SendKeys(searchValue);
                  
                    var searchResultPanel = WaitForElementPresent(WindowPanel, By.ClassName("fromMultiselect"));
                 
                    if (action.notMatchTip == null)
                    {
                        Waitloading(searchResultPanel);
                        Assert.IsTrue(IsElementExist(searchResultPanel, searchValue, "ux-mselect-noborder-item", true), "In the search text field enter the value " + searchValue + " can't be searched");
                    }
                    else
                    {
                        Waitloading(searchResultPanel);
                        Assert.IsTrue(IsElementExist(searchResultPanel, notMatchTip, "ux-mselect-noborder-item", true), "Not match value " + searchValue + " hasn't not match tip");
                    }
              
                    searchInputElement.SendKeys(new string((char)8, 40));
                    WaitDeleteSearchResults(searchResultPanel);
                   
                }
            }

TAG:

icy.qin的个人空间 引用 删除 icy.qin   /   2013-11-12 19:08:58
你这个帮了我很大的忙!我浏览http://19lou.com的时候,能用document.documentElement.scrollTop=10000把浏览器的滚动条往下拉,但是浏览sharepoint网站的时候就不行,用了你的方法就解决了我的问题,多谢!!!
 

评分:0

我来说两句

Open Toolbar