[英]I want Do - While Loop including If Else Statement
您好需要對此的回應...
我有用於1.打開Firefox的代碼2.插入用戶名和密碼
檢查這些參考圖像
轉到https://mettl.com/corporate/live-feed#/proctoringDashboard
一旦找到候選名稱或電子郵件地址,而不是“沒有其他候選者正在等待授權”,請等待10秒,然后等待鼠標單擊
像下面
例如
我們有100位在線候選人,當更正了候選人的詳細信息后,我將復制姓名,電子郵件ID和出生日期,如果未更正,則返回所有測試
請檢查我的以下代碼
package com.selenium.wipro.sample;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExampleScanrio {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Yaser\\dist\\geckodriver-master\\geckodriver.exe");
File pathBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxbinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxbinary));
WebDriver driver = new FirefoxDriver(options);
driver.get("https://mettl.com/corporate/login");
driver.manage().window().maximize();
driver.findElement(By.name("userName")).sendKeys("sometext");
driver.findElement(By.name("password")).sendKeys("sometext");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.navigate().to("https://mettl.com/corporate/live-feed#/proctoringDashboard");
WebDriverWait wait = new WebDriverWait(driver,50);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='pull-left']")));
// Click -> AllTests
driver.findElement(By.xpath("//span[@class='pull-left']")).click();
// Click -> Authorize
driver.findElement(By.xpath("//button[contains(text(),'Authorize')]")).click();
// Find String
String tt = "No more candidates awaiting Authorization";
String nomore = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='ng-scope' and contains(@data-ng-if,'newRequestReceived')]//p[@class='ng-scope' and contains(@data-ng-if,'authRequestCount')]"))).getAttribute("innerHTML");
// i need condition Statement and Loop Statement here
// It might be wrong please give a correct Statement
boolean run = true;
while(run)
{
if (nomore.contentEquals(tt))
{
driver.navigate().to("https://mettl.com/corporate/live-feed#/proctoringDashboard");
//Thread.sleep(750);
driver.findElement(By.xpath("//label[@class='checkbox ng-binding']//input[@type='checkbox']")).click();
driver.findElement(By.xpath("//button[contains(text(),'Authorize')]")).click();
Thread.sleep(1200);
System.out.println("Not Available");
}
else
{
System.out.println("Available");
//Thread.sleep(10000);
run = false;
//break;
}
}
}
}
和這樣的錯誤
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 63.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 20324, moz:profile: C:\Users\Yaser\AppData\Loca..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 39efeef7-4514-4b83-b31b-deaf937ee098
*** Element info: {Using=xpath, value=//label[@class='checkbox ng-binding']//input[@type='checkbox']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at automation.ExampleScanario.main(ExampleScanario.java:52)
請幫助我解決這個問題,我不是軟件工程師,請考慮一下我的英語知識和Java初學者
最后
當候選數據顯示在窗口中時
將這些日期復制到記事本
Xpath位置
//span[@title='First Name']
//span[@title='Date of Birth']
//span[@title='Email Address']
謝謝
Yaser B
我不明白您到底想做什么,但是請嘗試以下循環:
boolean run = true;
while(run){
if(statement){
Do something
}else{
Do something else
}
}
這是一個無限循環; 為了避免這種情況,可以將run設置為false,它將停止。
真誠的Silvan
它應該像這樣工作:
String tt = "No more candidates awaiting Authorization";
String nomore = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='ng-scope' and contains(@data-ng-if,'newRequestReceived')]//p[@class='ng-scope' and contains(@data-ng-if,'authRequestCount')]"))).getAttribute("innerHTML");
boolean run = true;
while(run)
{
if (nomore.contentEquals(tt))
{
driver.navigate().to("https://mettl.com/corporate/live-feed#/proctoringDashboard");
driver.findElement(By.xpath("//label[@class='checkbox ng-binding']//input[@type='checkbox']")).click();
driver.findElement(By.xpath("//button[contains(text(),'Authorize')]")).click();
Thread.sleep(750);
System.out.println("Not Available");
}
else
{
System.out.println("Available");
//Thread.sleep(10000);
//break;
run = false; /*Stopps the loop*/
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.