Reputation: 125
I'm working with an old portal and I have to use IE
. There are some things that it doesn't find, cause it's part of a <td>
menu, I tried to find it by XPath
, but doesn't help.
I found the form is being rendered by a JavaScript
function. And I'd like to click on them just to execute it, but how can I locate the page elements using selenium WebDriver
??
For example: if I had this code
<div class="logout-link ng-scope"
ng-click="login("github")"
ng-show="!me" ng-controller="MenuCtrl">login</div>
How can I execute the ng-click part with the Selenium WebDriver?
Upvotes: 2
Views: 2799
Reputation: 23805
Why do you want to execute Javascript
to locate an element??? Try using WebDriverWait
to wait until element visible and clickable as below :-
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var Login = wait.Until(ExpectedConditions.ElementToBeClickable(By.Xpath("//div[text() = 'login']")));
Login.Click();
Note :- make sure before try this element is not inside any frame
Hope it helps.....:)
Upvotes: 0
Reputation: 92
Clicking on the web element you create executes the associated function. Look via CSS Selector against the ng-click:
IWebElement elem = driver.FindElement(By.CssSelector("div[ng-click=login("github")]"));
elem.click();
You could also build an action to move to the element and then click on it:
IWebElement elem = driver.FindElement(By.CssSelector("div[ng-click=login("github")]"));
Actions action = new Actions(driver);
action.MoveToElement(elem).Click().Build().Perform();
Upvotes: 0
Reputation: 665
Upvotes: 1