如何使用Selenium和C#删除元素属性? [英] How to remove an element attribute using Selenium and C#?

查看:162
本文介绍了如何使用Selenium和C#删除元素属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我要从中删除 disabled = disabled并关闭开发工具窗口的html块。 iam将selenium-webdriver与c#一起使用。
谢谢。

below is the chunk of html from which i want "disabled="disabled"" deleted and close the dev tools window. iam using selenium-webdriver with c#. Thank you.

<a class="btn btn-success" href="javascript:;" id="SendRFQ" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Processing..." disabled="disabled" onclick="return SubmitRequisitionData(&quot;Submitted&quot;)">Click to Submit</a>


推荐答案

删除/删除属性,其 disabled = disabled ,因为该元素为启用了JavaScript 的元素,您需要使用 WebDriverwait 使元素可见,并且您可以使用以下任一解决方案:

To delete/remove the attribute and it's value of disabled="disabled" as the element is JavaScript enabled element you need to use WebDriverwait for the element to be visible and you can use either of the following solutions:


  • 使用 PartialLinkText

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible(By.PartialLinkText("Click to Submit")));
    ((IJavascriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('disabled')", element);
    


  • 使用 CssSelector

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible(By.CssSelector("a.btn.btn-success#SendRFQ")));
    ((IJavascriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('disabled')", element);
    


  • 使用 XPath

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible(By.XPath("//a[@class='btn btn-success' and @id='SendRFQ']")));
    ((IJavascriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('disabled')", element);
    


  • 这篇关于如何使用Selenium和C#删除元素属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆