转载请注明出自天外归云的博客园: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. Lintcode: Matrix Zigzag Traversal

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-or ...

  2. linux第13天 生产者与消费者

    pthread_cond_t   my_condition = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INIT ...

  3. ansible自动化运维工具的安装与使用

    运行环境 centOS6.6 ansible ansible的功能还是比较多的,博主只用它在集群上进行批量部署软件和维护的功能,其他不多做研究,有需要的话这篇文章会慢慢补充. ansible特点 轻量 ...

  4. 如何将扩展名为.backup的文件导入postgresql中 求步骤 新手 谢谢.

    1.到www.postgresql.org下载pgadmin这个工具,安装好2.在菜单-文件-新增服务器 名称:TEST-PGSQL(名称自己编) 主机:填上你postgresql数据库的服务器ip地 ...

  5. DOM事件处理有三个阶段

    DOM事件处理有三个阶段: 捕捉阶段(capture phase):从最上层元素,直到最下层(你点击的那个target)元素.路过的所有节点都可以捕捉到该事件. 命中阶段(target phase): ...

  6. bash广播

    terminal1$: mkfifo script_name terminal2$: cat script_name terminal1$: script -f script_name 可以发广播到t ...

  7. full_case & parallel_case

    case中的full_case与parallel_case讨论: 1)术语介绍: 整个case模块叫做:case_statement,注释部分叫做case_statement_header case ...

  8. [软件推荐]转换html到chm的软件,winchm pro

    之前使用teleport pro抓取过好几个网站的内容,网页文件都是在一个文件夹里,但是转换成chm格式的会方便一些. 用过一款软件叫easychm,是国人开发的.但是没注册的版本会在生成的文件中自动 ...

  9. [CrunchBang]Linux系统下必要的中文字体

    sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai ttf-arphic ...

  10. Servlet工作原理(转)

    Servlet运行在Servlet容器中,由容器负责Servlet实例的查找及创建工作,并按照Servlet规范的规定调用Servlet的一组方法,这些方法也叫生命周期的方法.具体调用过程如下图所示: ...