【发布时间】:2019-04-15 06:10:51
【问题描述】:
需要从下拉列表中选择。如果选择是,我需要填写某些文本字段,如果没有,则需要填写其他文本字段。使用 selenium java,我需要有关如何编写 if else 语句的帮助。 我已输入完整代码供您参考。
在此处输入代码
<WebElement JointApplication=driver.findElement(By.id("-1-1-joint_life"));
Select Joint=new Select(JointApplication);
Joint.selectByVisibleText("No");
Thread.sleep(6000);
if(driver.findElement(By.xpath("//SELECT[contains(@style,'width: 102%;')]")).isDisplayed())
{
// if we select yes for Joint Application
WebElement Title=driver.findElement(By.id("dd-2-1-title1"));
Select Tit=new Select(Title);
Tit.selectByVisibleText("Mr");
driver.findElement(By.id("-2-1-fullname1")).sendKeys("Test ");
driver.findElement(By.id("-2-1-csurname1")).sendKeys("Automatioan");
driver.findElement(By.id("-2-1-nino")).sendKeys("SK119944B");
driver.findElement(By.id("-1-d_o_b1")).sendKeys("01");
driver.findElement(By.id("-1-d_o_b2")).sendKeys("01");
driver.findElement(By.id("-1-d_o_b3")).sendKeys("1990");
}
else
{
WebElement COB=driver.findElement(By.id("-2-1-cntry_bth"));
Select birth=new Select(COB);
birth.selectByVisibleText("United Kingdom");
driver.findElement(By.id("-2-1-place_bth")).sendKeys("London");
Thread.sleep(2000);
WebElement Nationality=driver.findElement(By.id("-2-1-nat_ality"));
Select Nation=new Select(Nationality);
Nation.selectByVisibleText("United Kingdom");
}>
【问题讨论】:
-
帮忙写什么?
-
我正在使用 if else 语句,它没有执行 if else 语句。我只能执行一条语句
-
你确定吗?
if和else块中的代码完全相同。 -
我的测试要求是,当应用程序联合时,它有不同的文本字段,如果是单个应用程序,则有差异字段。代码是正确的,但我正在努力使用 java 逻辑
-
@Arjun 您的代码说:“如果这个 contition 是真的,那么做这个,如果它不是真的,做同样的事情”。它应该这样做吗?
标签: java selenium selenium-webdriver automation automated-tests