4

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>

2 Answers 2

4

Try below code to remove attribute from element

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("document.querySelector('a.btn.btn-success').removeAttribute('disabled')");

P.S. Note that real user will not modify HTML DOM to make link enabled, so if you need your script to simulate user-like behavior you should find another approach to make element enabled...

Sign up to request clarification or add additional context in comments.

Comments

2

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:

  • Using 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);
    
  • Using 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);
    
  • Using 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);
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.