簡體   English   中英

我想寫在文本框中,如果它顯示在頁面上,如果它沒有顯示在頁面上,則單擊下一步按鈕,然后直接單擊下一步按鈕

[英]i want to write in textbox if it is display on page and click on next button if it is not display on the page then directly click on next button

if(!driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).isEnabled())
{   
    System.out.println("IS NOT DISPLAYED"); // if text box is display
    driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();
}
else if(driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).isEnabled())
{           
    System.out.println("IS DISPLAYED"); // if text box is not display
    driver.findElement(By.id("pt1:r1:0:r1:2:r1:0:it1::content")).sendkey("ABCXYZ");
    driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();
}

我試過 try 和 catch 阻止它的工作,但執行腳本需要時間。

簡單解釋一下,你要做的是: 1.檢查頁面上是否存在文本框...如果存在,將文本放入其中。 2.點擊下一步按鈕。

無論復選框是否存在,您仍然單擊下一個按鈕,以便將其拉到if之外。

List<WebElement> textboxes = driver.findElements(By.id("pt1:r1:0:r1:2:r1:0:it1::content"));
if (!textboxes.isEmpty())
{
    // textbox exists
    textboxes.get(0).sendKeys("ABCXYZ");
}

driver.findElement(By.id("pt1:r1:0:r1:2:next")).click();

如果您要重用定位器( By s),我建議您將它們存儲在一個變量中,例如

By nextButtonLocator = By.id("pt1:r1:0:r1:2:next");
driver.findElement(nextButtonLocator).click();

我建議您閱讀一些有關 Java 編程的教程以提高您的編程知識。 您還可以獲得一些非常好的 Java 書籍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM