import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import java.util.HashMap; public class UniMarburgPage extends Page { private static final By LANGUAGE_SELECTOR = By.cssSelector(".language > a"); public UniMarburgPage(WebDriver driver) { super(driver); } public void changeLanguageToEnglish() { JavascriptExecutor js = (JavascriptExecutor) driver; HashMap vars = new HashMap<>(); vars.put("lang", driver.findElement(LANGUAGE_SELECTOR).getText()); if ((Boolean) js.executeScript("return (arguments[0] === \'ENGLISH\')", vars.get("lang"))) { driver.findElement(LANGUAGE_SELECTOR).click(); } } }