本文整理汇总了C#中this.Click方法的典型用法代码示例。如果您正苦于以下问题:C# this.Click方法的具体用法?C# this.Click怎么用?C# this.Click使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckTheCheckbox
public static void CheckTheCheckbox(this IWebElement element, bool isWantChecked)
{
if (isWantChecked)
{
if (!element.Selected)
element.Click();
}
else
{
if (element.Selected)
element.Click();
}
}
示例2: ClickAndWait
public static void ClickAndWait(this IWebElement element, double timeoutInSeconds)
{
if (!(timeoutInSeconds > 0)) return;
var timeout = timeoutInSeconds * 1000;
element.Click();
Thread.Sleep(Convert.ToInt32(timeout));
}
示例3: ClickLink
public static void ClickLink(this IWebElement link)
{
if (link == null)
throw new ArgumentNullException("link");
bool exceptionCaught;
do
{
exceptionCaught = false;
try
{
// sometimes, clicking a button or hyperlink does not work in IE / Chrome
// solution is to click only for FF, and use enter key for IE / Chrome
if (link.Browser().IsInternetExplorer() || link.Browser().IsFirefox())
{
link.SendKeys(Keys.Enter);
}
else
{
link.Click();
}
}
catch (WebDriverException)
{
exceptionCaught = true;
}
} while (exceptionCaught);
}
示例4: ClickButton
public static void ClickButton(this IWebElement button)
{
if (button == null)
throw new ArgumentNullException("button");
bool exceptionCaught;
do
{
exceptionCaught = false;
try
{
// sometimes, clicking a button or hyperlink does not work in IE / Chrome
// solution is to click only for FF, and use enter key for IE / Chrome
if (!button.Browser().IsInternetExplorer())
{
200.WaitThisManyMilleseconds();
button.Click();
}
else
{
button.SendKeys(Keys.Enter);
}
}
catch (WebDriverException)
{
exceptionCaught = true;
}
} while (exceptionCaught);
}
示例5: ClickAndWait
public static IWebElement ClickAndWait(this IWebElement element, TimeSpan? time = null)
{
time = time ?? TimeSpan.FromSeconds(1);
element.Click();
Thread.Sleep(time.Value);
return element;
}
示例6: WaitUntilElementBecomeClickableAndClick
public static void WaitUntilElementBecomeClickableAndClick(this IWebElement element)
{
var driver = TestEnvironment.Instance.WebDriver;
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, TestEnvironment.Instance.WaitLongRequestTimeout));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
element.Click();
}
示例7: ClickLink
/// <summary>
/// Clicks the link.
/// </summary>
/// <param name="me">Me.</param>
/// <param name="subDomain">Sub domain.</param>
static void ClickLink(this IWebElement me, string subDomain = null, bool addParams = false)
{
//
// We check the href on me and modify it before clicking (ie. www.google.com -> stage.google.com).
//
string href = me.GetAttribute("href");
Console.WriteLine("ClickLink before '{0}'", href);
if (subDomain != null) {
if (href != null) {
Uri uri = new Uri(href);
string oldSubDomain = uri.Host.Split('.')[0];
string[] notReplaceSubDomains = new string[] { "secure" };
if (!href.Contains("#") && !(oldSubDomain.Equals(subDomain)) && !notReplaceSubDomains.Contains(oldSubDomain)) {
Console.WriteLine("Replacing subdomain '{0}' with '{1}'", oldSubDomain, subDomain);
string newHref = href.Replace(oldSubDomain, subDomain);
if (addParams) {
newHref = HttpExtensions.AddQuery(newHref, "param", "value");
}
IWebDriver driver = Factory.Instance;
IJavaScriptExecutor js = ((IJavaScriptExecutor)Factory.Instance);
js.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2]);", me, "href", newHref);
}
}
}
href = me.GetAttribute("href");
Console.WriteLine("ClickLink after '{0}'", href);
me.Click();
}
示例8: click
public static void click(this IWebElement field)
{
if (!field.Enabled && !field.Displayed)
{
throw new ElementNotVisibleException("The element passed is not displayed/enabled");
}
field.Click();
}
示例9: LogOn
public static void LogOn(this INativeActionSyntaxProvider I, string userName, string password)
{
I.Open(UrlHelper.BaseUrl + "users/account/LogOn");
I.Expect.Url(x => x.LocalPath.Contains("LogOn"));
I.Enter(EnvironmentSettings.TestAccountName).In("#SignIn_UserNameOrEmail");
I.Enter(EnvironmentSettings.TestAccountPassword).In("#SignIn_Password");
I.Click("#signin-link");
}
示例10: click
public static Link click(this Link link, int miliseconds)
{
if (link != null)
{
link.Click();
miliseconds.sleep();
}
return link;
}
示例11: BrowserSpecificCheck
public static IWebElement BrowserSpecificCheck(this IWebElement element, IWebDriver webDriver) {
if (webDriver is InternetExplorerDriver) {
element.SendKeys(Keys.Space);
}
else {
element.Click();
}
return element;
}
示例12: ClickSubMenu
/// <summary>
/// Uses jquery to trigger a mouseover event. Then clicks the submenu link.
/// </summary>
/// <param name="cssLocator">Css locator of the parent menu.</param>
public static void ClickSubMenu(this IWebElement element, string cssLocator)
{
var script = String.Format(@"$('{0}').trigger('mouseover');", cssLocator);
IJavaScriptExecutor js = (IJavaScriptExecutor)Browser.Driver;
js.ExecuteScript(script);
element.Click();
script = String.Format(@"$('{0}').trigger('mouseout');", cssLocator);
js.ExecuteScript(script);
}
示例13: UploadPackageUsingUI
public static void UploadPackageUsingUI(this INativeActionSyntaxProvider I, string fullPackagePath)
{
// Navigate to the Upload Package page. This will fail if the user never uploaded the previous package, hence the error handling.
I.Open(String.Format(UrlHelper.UploadPageUrl));
try
{
I.Expect.Url(x => x.AbsoluteUri.Contains("/packages/Upload"));
}
catch
{
I.Click("a[class='cancel']");
}
// Upload the package.
I.Click("input[name='UploadFile']");
I.Wait(5);
I.Type(fullPackagePath);
I.Press("{ENTER}");
I.Wait(5);
I.Click("input[value='Upload']");
}
示例14: ClickUsingMouse
/// <summary>
/// Click on the element using Actions API. 'Click' method is known to not work in same strange cases on Edge,
/// Use this method instead
/// </summary>
public static void ClickUsingMouse(this IWebElement element, IWebDriver driver)
{
ICapabilities capabilities = ((RemoteWebDriver) driver).Capabilities;
if (capabilities.BrowserName == "Firefox")
{
element.Click();
}
else
{
new Actions(driver).Click(element).Build().Perform();
//does not work with Firefox 48, Selenium 3.0.0-beta2, GeckoDriver.exe 0.10.0
}
}
示例15: CostCenterComboBoxSelector
public static void CostCenterComboBoxSelector(this ComboBox comboBox, string elementToSelect)
{
if (comboBox != null)
{
comboBox.Click();
comboBox.Select(elementToSelect);
Console.WriteLine(elementToSelect + " Selected");
}
else
{
Console.WriteLine(elementToSelect + " not found");
}
}