Reputation: 63
I need to click a link in a page with Selenium-webdriver , but i can't access the element using the value of href
like below:
var link = WebDriver.FindElements(By.XPath("//a[@href='example.html']"));
because elements in the page is in a frame and in the source of another page. So I need to click to a specific coordinate where the link is. How can I make it by using selenium webdriver.
Upvotes: 1
Views: 4242
Reputation: 5819
It sounds like what you need to be able to do is switch to a different frame then look in that frame for the element you want rather than using co-ordinates. the problem with co-ordinates is that if you run it on a different machine the co-ordinates could be different.
IWebElement frame = driver.FindElement(By.CssSelector("xxx"));
driver.SwitchTo().Frame(frame);
then search for your element as normal. then once you are done call
driver.SwitchTo().DefaultContent();
and you will be back to the original page.
Upvotes: 4
Reputation: 27506
You can do that through the Actions class.
Actions builder = new Actions(driver);
builder.MoveByOffset(x, y).Click().Perform();
Or alternatively via JavascriptExecutor
, just pass to it JS code needed to move to the link and click it.
Upvotes: 2