C
C
Chvalov2019-03-24 23:47:38
Java
Chvalov, 2019-03-24 23:47:38

How to bring this code into a more beautiful form or into a switch case?

I am looking for a form by id, name, classand actionwhich matches the regular expression.
If this is found, I pass the current WebElement to the direct method for further tests
. But the use confuses me if- else ifsince their number only increases with time.

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("Сегодня нету нужных форм...");
}

How to rewrite in a more beautiful / convenient form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-03-24
@Chvalov

Push the regexps and the corresponding attributes into an array and run with a simple foreach.
If the reaction to a positive response can be different, then you can use a dictionary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question