<a href="javascript:;" class="btn green request-action-btn" data-request-status="Approved" data-id="212"> Approve </a>
How can I get this element in selenium C#. I tried by:href ,Xpath, ID, class name, text name but I couldn't get this element
<a href="javascript:;" class="btn green request-action-btn" data-request-status="Approved" data-id="212"> Approve </a>
How can I get this element in selenium C#. I tried by:href ,Xpath, ID, class name, text name but I couldn't get this element
you can click by Link text
driver.FindElement(By.LinkText("Approve")).Click();
or by CSS Selector
.btn.green.request-action-btn
To identify the element you can use the following Locator Strategy:
CssSelector:
driver.FindElement(By.CssSelector("a.btn.green.request-action-btn[data-request-status='Approved']"))
XPath:
driver.FindElement(By.XPath("//a[@class='btn green request-action-btn' and @data-request-status='Approved']"))
XPath using contains():
driver.FindElement(By.XPath("//a[@class='btn green request-action-btn'][contains(.,'Approve')]"))
XPath using normalize-space():
driver.FindElement(By.XPath("//a[@class='btn green request-action-btn'][normalize-space()='Approve']"))
It can be found by using tagName as below:
ReadOnlyCollection<IWebElement> anchrTags= driver.FindElements(By.TagName("a"));
IWebElement roWebElement = anchrTags.Where(x => x.Text == "Approve").FirstOrDefault();
Otherwise if the anchor tag exists in the frames, it will not found. try switching to that frame:
IWebElement iframe = driver.FindElements(By.Id("iframeId"));
driver.SwitchTo().Frame(iframe);
IWebElement roWebElement = anchrTags.Where(x => x.Text == "Approve").FirstOrDefault();