Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: A function which only searches for displayed elements #213

Open
1 of 2 tasks
adrian-tankard-senetas opened this issue Oct 5, 2022 · 6 comments
Open
1 of 2 tasks
Labels
enhancement New feature or request

Comments

@adrian-tankard-senetas
Copy link

Description

Given the website I work on has 4 duplicate elements for each field
And only 1 of the 4 elements are displayed at any one time
And none of the elements in the DOM contain any details that specify if the element is displayed
When I search for the element using the L() function
Then (I think) only the 1st element is returned which is not displayed
NEW FEATURE: Then I can use a function which only returns displayed fields

Alternatives

Currently I have written an interaction which searches for the field
And then I filter out the hidden fields
So my interaction to fill in a field looks like this:

public class FillInField : ITask
{
    public string Phrase { get; }
    public string TextToSend { get; }

    private FillInField(string phrase, string textToSend)
    { Phrase = phrase; TextToSend = textToSend; }
      

    public static FillInField For(string phrase, string textToSend) =>
      new FillInField(phrase, textToSend);

    public void PerformAs(IActor actor)
    {
        var driver = actor.Using<BrowseTheWeb>().WebDriver;
        var fieldList = driver.FindElements(By.XPath(Phrase));
        var displayedField = fieldList.FirstOrDefault(c => c.Displayed == true);

        displayedField?.SendKeys(TextToSend);
    }
}

Anything else?

No response

Commitments

  • I agree to follow Boa Constrictor's Code of Conduct.
  • I want to work on this issue myself. (This is voluntary, not required.)
@adrian-tankard-senetas adrian-tankard-senetas added the enhancement New feature or request label Oct 5, 2022
@CoffeeAtBedtime
Copy link
Contributor

🤔 @adrian-tankard-senetas are you able to share an example of the elements as they appear in the DOM? If they are there but some are visible on the page and others are not there has to be some sort of attribute, property or CSS that is affecting this. If so the Path could be updated to include this condition and bypass the need to do the filtering.

@adrian-tankard-senetas
Copy link
Author

adrian-tankard-senetas commented Dec 4, 2022 via email

@CoffeeAtBedtime
Copy link
Contributor

CoffeeAtBedtime commented Dec 4, 2022

After looking at this I see 18 form inputs on your page in the Chrome console when I query. The difference between what is displayed and not displayed is the presence of a parent element with the css class "ng-hide". I would update your xpath to exclude any parent divs that may have ng-hide in them prior to an input element. This should do the filtering for you.
Screenshot 2022-12-04 at 4 14 43 PM
Screenshot 2022-12-04 at 4 20 44 PM

@adrian-tankard-senetas
Copy link
Author

adrian-tankard-senetas commented Dec 4, 2022 via email

@CoffeeAtBedtime
Copy link
Contributor

CoffeeAtBedtime commented Dec 4, 2022

You would be including early in your xpath a check for any parent div of these form input elements to not have the css class ng-hide. It will be something like /div[not(contains(@class, "ng-hide"))] watch this video for better understanding https://www.youtube.com/watch?v=dPluub64PIE experiment with your usage of absolute and relative in your xpath https://stackoverflow.com/questions/43100052/difference-between-and-in-xpath.

@AutomationPanda
Copy link
Contributor

My gut reaction is to agree with @CoffeeAtBedtime. Filtering for visible elements can be done entirely within the locator's query.

However, I think there might be a deeper opportunity here for richer locators. Right now, the locator class essentially just holds the query. What if it could hold properties like shadow DOM roots and filters like being displayed? This might dovetail nicely with our plans to support shadow DOM in Boa Constrictor 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants