SharePoint自动化系列——Select-option标签的定位方法总结
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/
C#中通过Selenium定位页面上的select-option结构,尝试了以下几种方法,均没有生效:
//iw.FindElement(By.CssSelector("select#id > option[value='']")).Click();
//iw.FindElement(By.XPath("//select[@id='']/option[@value='']")).Click();
//iw.FindElements(By.TagName("option"))[index].Click();
最后通过以下这种方式,成功定位到了页面上的Select-option标签:
var selector = iw.FindElement(By.Id(""));
SelectElement select = new SelectElement(selector);
select.SelectByText("text");
Select对象可以通过option的value,text等属性对元素进行定位。
实际应用,如在SharePoint中创建site时,对于site template的选取和site path的选择:
public IWebDriver CreateSPSite(IWebDriver iw, string caUrl,string title,string template)
{
string createSitePage = caUrl + "/_admin/createsite.aspx";
iw.Navigate().GoToUrl(createSitePage);
WaitUntilPageLoadedID(iw, "ctl00_PlaceHolderMain_ctl02_RptControls_BtnCreateSite");
//Title.
iw.FindElement(By.Id("ctl00_PlaceHolderMain_idTitleDescSection_ctl01_TxtCreateSiteTitle")).SendKeys(title);
//Url.
var paths = iw.FindElement(By.Id("ctl00_PlaceHolderMain_ctl01_ctl04_DdlWildcardInclusion"));
SelectElement path = new SelectElement(paths);
path.SelectByText("/sites/");
WaitUntilPageLoadedID(iw, "ctl00_PlaceHolderMain_ctl01_ctl04_TxtSiteName");
iw.FindElement(By.Id("ctl00_PlaceHolderMain_ctl01_ctl04_TxtSiteName")).SendKeys(title);
switch (template)
{
case "ts":
break;
case "edi":
iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_tabid1")).Click();
Thread.Sleep(1000);
WaitUntilPageLoadedID(iw, "ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate");
var selector = iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate"));
SelectElement select = new SelectElement(selector);
select.SelectByText("eDiscovery Center");
break;
case "rc":
iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_tabid1")).Click();
Thread.Sleep(1000);
WaitUntilPageLoadedID(iw, "ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate");
selector = iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate"));
select = new SelectElement(selector);
select.SelectByText("Records Center");
break;
case "holdCenter":
iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_tabid1")).Click();
Thread.Sleep(1000);
WaitUntilPageLoadedID(iw, "ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate");
selector = iw.FindElement(By.Id("ctl00_PlaceHolderMain_InputFormTemplatePickerControl_ctl00_ctl01_LbWebTemplate"));
select = new SelectElement(selector);
select.SelectByText("In-Place Hold Policy Center");
break;
}
iw.FindElement(By.Id("ctl00_PlaceHolderMain_idPrimaryAdministratorSection_ctl01_PickerOwner_upLevelDiv")).SendKeys(@"userName");
iw.FindElement(By.Id("ctl00_PlaceHolderMain_ctl02_RptControls_BtnCreateSite")).Click();
return iw;
}
对应在页面上的操作,第一段灰色部分的代码对如下标签进行了选择:
第二段灰色部分代码对如下标签进行了选择:
SharePoint自动化系列——Select-option标签的定位方法总结的更多相关文章
- SharePoint自动化系列——Site/Web/List级别的导航菜单
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...
- SharePoint自动化系列——创建MMS terms
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Web
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...
- SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow
Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...
- SharePoint自动化系列——Add content type to list.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...
- SharePoint自动化系列——Add/Remove "Record" from items
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 目的:批量的将SharePoint items变成records或者将records变成普通的it ...
- SharePoint自动化系列——Content Type相关timer jobs一键执行
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...
- SharePoint自动化系列——Create a local user and add to SharePoint
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...
随机推荐
- nyist 673 悟空的难题
http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ...
- 使用console进行 性能测试 和 计算代码运行时间(转载)
本文转载自: 使用console进行 性能测试 和 计算代码运行时间
- paper 49:论文退稿?审稿人帮你总结了22个能避免的常见问题
很多投稿出去的文章都是可上可下的.往往退稿的时候,审稿人提了一堆意见,说退稿.但是大家想过没有?如果能事先预测到这些意见,或者请懂行的人事先看过文章预测出意见,然后根据这些意见修改好了再投出去,说不定 ...
- JQ 获取单选按钮选中的值
==========================html 代码 <input type="radio" style="float: left " on ...
- cocos2dx建立项目
http://www.cocos.com/doc/article/index?type=wiki&url=/doc/cocos-docs-master/manual/framework/nat ...
- 【DP水题】投票问题(二)
投票问题(一) [试题描述] 欧阳文和欧阳武竞选学联主席,汪梁森负责唱票,共有m+n张,结果欧阳文获胜,已知欧阳文和欧阳武分别获得 m 张票和 n 张票(m>n).现在请你计算在唱票过程中欧阳文 ...
- 视频处理控件TVideoGrabber中如何混合多个视频源(1)
其实一个或是几个作为普通的视频源使用的TVideoGrabber组件,可以进行混合来作为一个TVideoGrabber组件使用,这些普通的组件可以是视频捕捉设备或是视频剪辑等.同时这个混合的组件独立于 ...
- Android使用Application总结
对于application的使用,一般是 在Android源码中对他的描述是; * Base class for those who need to maintain global applicati ...
- 这个Glance的界面该怎么看出问题,为什么状态是SOCKT?
这个glance的状态图有问题吗?
- DE1-SOC开发板上搭建NIOS II处理器运行UCOS II
DE1-SOC开发板上搭建NIOS II处理器运行UCOS II 今天在DE1-SOC的开发板上搭建NIOS II软核运行了UCOS II,整个开发过程比较繁琐,稍微有一步做的不对,就会导致整个过 ...