【发布时间】:2019-02-15 19:04:38
【问题描述】:
我只是对我遇到的问题提出了一个足够简单的问题。我正在尝试将字符串值设置为"0",如果不存在 web 元素,否则字符串是 webelement 值(使用getText)。但是,我似乎无法在 if 和 else 语句之外使用这些值。我该怎么做呢?
这是我的代码
String players_in_game = null;
public void join_game_user_increases_register() throws Exception {
WebDriverWait wait = new WebDriverWait(Drivers.getDriver(), 10);
wait.until(ExpectedConditions.visibilityOf(countdownLabel));
if (!num_of_players_in_game.isDisplayed()) {
String players_in_game = "0";
} else {
String players_in_game = num_of_players_in_game.getText();
}
System.out.println(players_in_game);
int first_num = Integer.parseInt(players_in_game);
【问题讨论】:
-
players_in_game已在第一行声明为String,因此请从 if 和 else 语句中删除它。
标签: java selenium if-statement testing automation