How to bring this code more in view or switch case?

Are you searching for form id,name,class and action which meets the regular expression.
If this was give the current WebElement method direct for further tests
But I am confused by the use of if - else if because with time their number is increasing.
if (formElements.getAttribute("action").matches(regexUser)) {
direct(formElements);
} else if (formElements.getAttribute("id").matches(regexMember)) {
direct(formElements);
} else if (formElements.getAttribute("name").matches(regexPeople)) {
direct(formElements);
} else if (formElements.getAttribute("class").matches(regexFollowers)) {
direct(formElements);
} else if (formElements.getAttribute("class").matches(regexUser)) {
direct(formElements);
} else {
 System.out.println("Today no need forms...");
}

How to rewrite in a more beautiful / comfortable look ?
March 19th 20 at 08:23
1 answer
March 19th 20 at 08:25
Solution
Stuff regexpi and the corresponding attributes in the array and to drive a simple foreach-eat.
If the response to a positive trigger can be different, it is possible to use a dictionary.
The reaction is always the same, if you pass true to the method of direct...

But I don't quite get how to implement what you wrote (

To make a two-dimensional array [attribute] [regex] ? - isobel44 commented on March 19th 20 at 08:28
Can be two-dimensional. You can store something like KeyValuePair, if there is in Java. You can make your container class with two fields and have it stored. - christ.Johnson96 commented on March 19th 20 at 08:31
@isobel44, Why array?

Need something like (further the pseudocode):
Set<Pair<String, String>> pairs = [
 {"action", regexUser},
 {"id" regexMember},
...
];

private void checkPairs() {
 for( Pair<String, String> p: pairs ) {
 if (formElements.getAttribute(p.getKey()).matches(p.getValue())) {
direct(formElements);
return;
 } 
 System.out.println("Today no need forms...");
}


This, in theory, be enough. - Wilbert_Dietrich commented on March 19th 20 at 08:34
@Wilbert_Dietrich, well, an array in this case is not the specific title of the collection, but rather it is the "pseudocode". It is clear that can Set you Array, you can <what else is there in Java>. It is a question of the specific implementation :-) - christ.Johnson96 commented on March 19th 20 at 08:37

Find more questions by tags SeleniumJava