【发布时间】:2014-09-21 02:05:43
【问题描述】:
我刚开始使用 Selenium Webdriver,我马上遇到了一个问题,涉及我试图选择/单击的按钮都没有 ID 并共享同一个类。
所以我想知道如何通过它们包含的独特文本来选择它们。
我正在考虑可能使用 css 选择器,但我不确定如何告诉它查找特定文本以选择元素。
我现在只有:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Internal;
namespace SeleniumTest1.Methods
{
public class HomePage
{
private readonly IWebDriver _browser;
public HomePage(IWebDriver browser)
{
_browser = browser;
}
public IWebElement SearchBox()
{
return _browser.FindElement(By.Id("searchBox"));
}
public void ImageButton()
{
_browser.FindElement(By.CssSelector("a")).Click();
}
}
}
到目前为止非常基本。
我在哪里有 CssSelector 我不确定是否有选择包含文本“xyz”的“a”。
我已经尝试过寻找方法但找不到任何东西,虽然我觉得这一定是以前提出的问题,谢谢。
【问题讨论】:
标签: c# selenium selenium-webdriver css-selectors