Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

Selenium Web Driver If-Else condition to choose button1 or button2 or button3

I'm just started to study Java if result6 = list6.toArray(result6)

  1. If result6[a] = 2 click button1
  2. If result6[a] = 3 click button2
  3. If result6[a] = 4 click button3
if (result6[a] == 2) 
   driver.findElement(By.xpath("//*[@id="row1"]/div[14]/img")).click(); 

if (result6[a] == 3) 
   driver.findElement(By.xpath("//*[@id="row2"]/div[14]/img")).click();   

if (result6[a] == 4)    
   driver.findElement(By.xpath("//*[@id="row3"]/div[14]/img")).click();   
question from:https://stackoverflow.com/questions/65919540/selenium-web-driver-if-else-condition-to-choose-button1-or-button2-or-button3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
String elementId;
switch(result6[a]) {
    case 2: elementId = "row1";
            break;
    case 3: elementId = "row2";
            break;
    case 4: elementId = "row3";
            break;
}
String xpath = String.format("//*[@id="%s"]/div[14]/img", elementId);
driver.findElement(By.xpath(xpath)).click();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...