转载请注明出自天外归云的博客园: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标签的定位方法总结的更多相关文章

  1. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  2. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  3. SharePoint自动化系列——通过PowerShell创建SharePoint Web

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  4. SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...

  5. SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

    Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...

  6. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  7. SharePoint自动化系列——Add/Remove "Record" from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 目的:批量的将SharePoint items变成records或者将records变成普通的it ...

  8. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  9. SharePoint自动化系列——Create a local user and add to SharePoint

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...

随机推荐

  1. navicat 的查询功能

    navicat的查询的位置在: 在编辑器界面写代码,代码完成后点左上角的运行. 代码: create(创建)  table(一个表) <xxx>尖括号内的内容必填——我要创建并查询一个名叫 ...

  2. SQL 2012 连接失败

  3. uva 10755 - Garbage Heap

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. Python基础(1)python+Eclipse+pydev环境搭建

    编辑器:Python 自带的 IDLE 简单快捷, 学习Python或者编写小型软件的时候.非常有用.         编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的 ...

  5. python在window下的Nginx部署

    Python版本3.21 安装nginx下载windows上的nginx最新版本,http://www.nginx.org/en/download.html.解压后即可.运行nginx.exe后本地打 ...

  6. C++之路进阶——codevs2366(朋友圈)

    2366 朋友圈 2012年省队选拔赛河北  时间限制: 10 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 在很久很久以前,曾经 ...

  7. Tostring(); 括号中的参数 格式化字符串

    最近在逛 msdn 发现    查到  getTypeCode 方法  看到里边居然有 tostring("D")这样的写法      运行了一遍 感觉可以显示值      然后就 ...

  8. ajax中网页传输(一)TEXT——带有删除功能的数据库表格显示练习

    网页之间传输的三种方式:TEXT.JSON.XML. 本章将讲解带有TEXT形势的ajax网页传输 第一:body部分代码 <title>ajax中TEXT讲解并且带有删除功能的表格< ...

  9. 经典SQL

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  10. SQl中drop与truncate的区别

    在对SQL的表操作时,我们因不同的需求做出相应的操作. 我来对比一下truncate table '表明'与drop table '表格名'的区别,跟大家一起学习. drop table '表格名'- ...