C# Selenium Webdriver:选择列表中具有特定范围标题的单选按钮

C# Selenium Webdriver:选择列表中具有特定范围标题的单选按钮,c#,dom,xpath,selenium-webdriver,C#,Dom,Xpath,Selenium Webdriver,我有下面的HTML,在我的ul中有2个项目。现在我想检查(单击)单选按钮,其中。在这个HTML中只有一个元素,但可以有更多 如何找到此元素 HTML示例: <ul id="ctl00_cpm_AlbumMain_thumbs" class="listAlbums clearfix nospace-bottom" mediastorepartnertype="extrafilm" style="height: 160px;"> <li id="ctl00_cpm_AlbumMai

我有下面的HTML,在我的ul中有2个项目。现在我想检查(单击)单选按钮,其中
。在这个HTML中只有一个元素,但可以有更多

如何找到此元素

HTML示例:

<ul id="ctl00_cpm_AlbumMain_thumbs" class="listAlbums clearfix nospace-bottom" mediastorepartnertype="extrafilm" style="height: 160px;">
<li id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0_handle" class="folderitemhandle" pagenr="1">
    <a title="Bekijk de foto's in dit album." href="/nl/myaccount/myphotos/album.aspx?albumid=2ab03151-7f88-4924-9471-248786ba46c0">
    <img id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0_handle_image" class="lazy" width="100" data-original="http://photos.myserver.com.stage/photos/nastemp1/volume1/8889361a-c9e5-4cbd-a5a3-bbf7612dd370/131016/4/8/48f1d74f-0e62-455a-ba60-2a64fc3ff2a6.thumb.jpg?upd=635175161317600000" alt="Bekijk de foto's in dit album." src="http://photos.myserver.com.stage/photos/nastemp1/volume1/8889361a-c9e5-4cbd-a5a3-bbf7612dd370/131016/4/8/48f1d74f-0e62-455a-ba60-2a64fc3ff2a6.thumb.jpg?upd=635175161317600000" style="display: inline;">
    </a>
    <label class="albumTitle">
        <input id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0_handle_box" type="radio" onclick="javascript:SelectFolder('ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0_handle','1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0');" name="ctl00$cpm$AlbumMain$1da02a93-76cd-46a5-8dfb-e841aedf4398|2ab03151-7f88-4924-9471-248786ba46c0_handle$" value="box">
        <span title="Test (2)">Test (2)</span>
    </label>
</li>
<li id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7_handle" class="folderitemhandle" pagenr="1">
    <a title="Bekijk de foto's in dit album." href="/nl/myaccount/myphotos/album.aspx?albumid=35b9a18d-6203-4fcb-a05f-decb8672d1c7">
    <img id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7_handle_image" class="lazy" width="100" data-original="http://photos.myserver.com.stage/photos/nastemp1/volume1/8889361a-c9e5-4cbd-a5a3-bbf7612dd370/131016/7/f/7f2efe77-7754-463e-8eb7-f2853cfa0f07.thumb.jpg?upd=635175162493870000" alt="Bekijk de foto's in dit album." src="http://photos.myserver.com.stage/photos/nastemp1/volume1/8889361a-c9e5-4cbd-a5a3-bbf7612dd370/131016/7/f/7f2efe77-7754-463e-8eb7-f2853cfa0f07.thumb.jpg?upd=635175162493870000" style="display: inline;">
    </a>
    <label class="albumTitle">
        <input id="ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7_handle_box" type="radio" onclick="javascript:SelectFolder('ctl00_cpm_AlbumMain_1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7_handle','1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7');" name="ctl00$cpm$AlbumMain$1da02a93-76cd-46a5-8dfb-e841aedf4398|35b9a18d-6203-4fcb-a05f-decb8672d1c7_handle$" value="box">
        <span title="SeleniumUpload (3)">Selenium... (3)</span>
    </label>
</li>

您要做的是使用
xpath
选择器。如果您想匹配确切的标题,可以使用类似于
/*/span[title=“SeleniumUpload”]
的方法。如果您只想匹配与之相近的内容,那么您需要研究使用
xpath
contains

来简化HTML会有很大帮助。我与HTML无关,因此无法对其进行任何更改。我只是想在问题的上下文中简化它。创建简化的场景可以让读者更容易地评估您的问题。好的,但是我仍然没有相同标签中的输入按钮的Id。看,对。很抱歉要做到这一点,您必须深入挖掘
xpath
DOM
的魔力。首先,你必须找到你刚找到的元素的父节点,然后你需要找到
input
节点,它是前面提到的父节点的子节点。我会给你一些代码和例子,但我不知道
C
。有些代码是有用的。不管怎样,我会把它改成C。只要有一个想法就好了。这是我第一次使用硒。谢谢你的帮助!将我的代码添加到主题中。我按类名“albumTitle”查找所有元素。此标签包含输入元素和跨度元素。但是,我在span title属性上得到一个空字符串。
var albums = driver.FindElements(By.ClassName("albumTitle")); 
Console.WriteLine("Found {0} photo-albums", albums.Count);
foreach (var we in albums)
{
var span = driver.FindElement(By.TagName("span"));
String title = span.GetAttribute("title"); // returns empty string, I need this title value
Console.WriteLine("we.text:'{0}' title:''{1}",we.Text, title);

// work around
if (we.Text.Contains("Seleni")) // I should be able to check on span title
{
  var input = we.FindElement(By.CssSelector("input[id*='ctl00_cpm_AlbumMain_']"));
  var id = input.GetAttribute("id");
  Console.WriteLine(we.Text + " Id:" + id);
}
}