如何,如果条件如何使用,如果在硒网络的驾驶员条件
driver.findelement(By.xpath("id").sendkey("");
在这里使用例如
.xplath(id=253).click else xpath(id=888).sendkey("admin");
如何,如果条件如何使用,如果在硒网络的驾驶员条件
driver.findelement(By.xpath("id").sendkey("");
在这里使用例如
.xplath(id=253).click else xpath(id=888).sendkey("admin");
尝试这种方式,首先找到webelement 253
,如果ID 253
不获得查找然后,您的代码执行跳转到catch
块。
try
{
WebElement element = driver.findElement(By.id("253"));
if(element.isDisplayed() && element.isEnabled())
{
element.click();
}
}
catch(Exception e)
{
WebElement element_1 = driver.findElement(By.id("888"));
if(element_1.isDisplayed() && element_1.isEnabled())
{
element_1.sendKeys("admin");
}
}
嘿我想在下拉列表中使用此代码如果用户点击前面例如我有2个选项在该列表中,如果用户selet 1st好的,如果用户选择第二个我如何编码?这些是我的代码,并希望使用别的也 WebElement元素= driver.findElement(By.id(“.//* [@ id ='service_autoinput_dropdown']/div [6]/div [1]”“)) ; WebElement element_1 = driver.findElement(By.id(“.//* [@ id ='service_autoinput_dropdown']/div [7]/div [2]”“)); 谢谢 – GHOST
thz其工作plz帮助我到我的另一个问题 – GHOST
等待90分钟我有很多问题 – GHOST
首先检查哪个元素在那里。无论是id = 253还是id = 888.我们可以简单地在java中使用findelements来实现这一点。
if(driver.findElements(by.xpath("//*[@id=253]")).size>0)
{
//element exists with id = 253
// do the stuff
} else
{
//element do not exist with id = 253.
//element with id - 888 exists
// do the stuff
}
希望这会有所帮助。谢谢。
如果'id'是253你想使用'click',并且如果'id'是888你想输入什么? – Guy
https://stackoverflow.com/a/45138343/8305604感谢它为我工作:D :) – sanjan