0

I am using Visual Studio 2015 as my IDE and I installed protractor(version 0.10.2) to my project. In my code below [TestMethod] public void Login() { IWebDriver driver = new ChromeDriver();
var ngDriver = new NgWebDriver(driver); ngDriver.Url = "https://weather.com"; ngDriver.FindElement(By.ClassName("user-login")).Click();
Now, I want to locate a 'Log In' button using buttonText locator. However, when I tried ngDriver.FindElement(NgBy.), only following options were displayed after NgBy.: Binding, Equals, ExactBinding, ExactRepeater, Model, ReferenceEquals, Repeater, SelectedOpion

When I tried this with WebStorm and Javascript, I was able to locate and work with button as below element(by.buttonText('Log In')).click();

Why isn't something like 'ButtonText' appear after NgBy.?

Even in Anthony Chu's blog, he is using Ngby.Input(), which I don't have in the list. Why am I missing all these locators?


I found that NgBy class under Protractor offers only followings: class NgBy

so maybe Protractor-net doesn't provide NgBy.ButtonText()? But it doesn't make sense to me. I think that I am still doing something wrong!

0

2 Answers 2

0

See comments from this pull request : https://github.com/bbaia/protractor-net/pull/22

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

1 Comment

That discussion does not explain the missing NgBys. As JP-3 mentions in his last comment, those methods are part of the original protractor project and it is questionable IMO to decide to not include them in the .Net port.
0

You are right, in the "main" Protractor-net fork (maintained by bbaia) some NgBys are missing when comparing to the original Protractor project.

Option1

You can usually instead use the normal .Net WebDriver By (e.g. XPath or CssSelector) to locate the elements:

Find button by inner text with XPath

Find button by attribute value and text with XPath

You may also find this valuable - Find element by case insensitive text with XPath

Option2

You can also write your own implementation using something like driver.FindElements(By.TagName("button")).Where(e => e.Text.Trim() == "Text").FirstOrDefault(); Note that in many cases this is much slower than using XPath though.

Option3

If, because you are porting code that is already using those methods, it is important to you to have them, you can try sergueik fork which does have the missing methods: https://github.com/sergueik/protractor-net

Note that it is further behind the main fork though - https://github.com/sergueik/protractor-net/network

1 Comment

Thanks Ory. I know it's a bit late. :)

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.