Selenium webdriver in c#-Unable click on hyperlink on frame

1.2k views Asked by At

I am doing automation using selenium Webdriver in c#.So in my application, after clicking on one link, there is frame opened on top of main browser window So i am able to read text on that frame, in short i can switch to that frame. Frame having many hyperlink, and i have to click on hyperlink named "Add/Change Admin Message". But i uses below code to click on link but it is scrolling down the frame in IE browser so click action is not performed.But its works fine in chrome browser.

Driver.FindElement(By.XPath("//a[contains(text(),'"+"Add/Change Admin Message"+"')]")).Click();

I have tried with xpath,cssselector,classname,Id,linktext,partial link text but no luck. Below is the DOM for that link, please help me .. Add/Change Admin Message

1

There are 1 answers

3
alecxe On BEST ANSWER

First, you need to switch to the frame where the link is:

Driver.SwitchTo().Frame("frame name or id");

Then, you can locate the link by partial link text:

Driver.FindElement(By.PartialLinkText("Add/Change Admin Message"));

With IE it is often something magical you should do, try clicking the link via javascript:

IWebElement link = Driver.FindElement(By.PartialLinkText("Add/Change Admin Message"));

IJavaScriptExecutor js = Driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", link);