question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request for ExpectedConditions.attributeContains and ExpectedConditions.attributeToBe

See original GitHub issue

Hi,

First of all, I tried to find any issue already opened with the same request or similar one. Could not find it so I’m adding this one. Link and close this one if it’s already opened.

For my Selenium projects I love to use the ExpectedConditions.attributeContains and/or ExpectedConditions.attributeToBe but in Protractor these are not implemented and in my opinion these are a must have.

In Angular a lot of element changes happen just by only changing the class attribute, in my case I have an element that when clicked has the ‘.active’ class if we click the next element this class disappears from the first one and moves to the second element. In the automation that I’m doing is critical as I check if the element is already active, if not give him a click to make it active, wait for the class to be present and then I do the actions that I want, but I hate to redefine the element just for the wait and I hate more to use sleeps in my code.

There is already in place the ExpectedConditions.textToBePresentInElementValue so what I’m proposing is just to do something similar but instead of checking only the attribute value, checks any element attribute passed by as argument:

attributeContains(elementFinder: ElementFinder, attribute: string, text: string): Function {
    let hasText = () => {
      return elementFinder.getAttribute(attribute).then((actualText: string): boolean => {
        return actualText.indexOf(text) > -1;
      }, falseIfMissing);
    };
    return this.and(this.presenceOf(elementFinder), hasText);
  }

and

attributeIs(elementFinder: ElementFinder, attribute: string, text: string): Function {
    let hasText = () => {
      return elementFinder.getAttribute(attribute).then((actualText: string): boolean => {
        return actualText === text;
      }, falseIfMissing);
    };
    return this.and(this.presenceOf(elementFinder), hasText);
  }

There’s no big impact just by adding these two methods. If you implement these two, also redefine textToBePresentInElementValue to use attributeContains and pass ‘value’ as argument. They do the same.

Hope you take this request in consideration for the next release.

Thanks, Marco

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
patarakccommented, Jul 2, 2018

Was this ever done or is there an available alternative? I need to wait for an attribute to equal a certain string, but haven’t found the way to do this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium wait for ExpectedConditions.attributeToBe is not ...
atributetobe will execute equals string method, so if there is something else inside style, it will fail, try with attribute contains:
Read more >
ExpectedConditions.attributeContains - Java - Tabnine
Waits for an AJAX request to complete and automatically unregisters the ... tagName("body")); waitFor(ExpectedConditions.and( // Make sure that only a ...
Read more >
Example usage for org.openqa.selenium.support.ui ...
In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions attributeContains. Prototype. public static ExpectedCondition< ...
Read more >
ExpectedConditions - Selenium
An expectation with the logical and condition of the given list of conditions. static ExpectedCondition<java.lang.Boolean>, attributeContains​(By locator, ...
Read more >
How to use attributeContains method of org.openqa.selenium ...
Your first 100 automation testing minutes are on us. Claim Now. Try LambdaTest. Most used method in ExpectedConditions. titleIs · titleContains ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found