Saya memiliki elemen berikut di halaman web saya:

<button id="btnPackageDownloadtopPackageTable1dde0fcb2-948b-4bbc-b347-40deb2f6034e"
 title="Download package" ng-style="{'display': ''}" 
 ng-show="!PackageManagementCtrl.downloadStartedForPackage['topPackageTable1dde0fcb2-948b-4bbc-b347-40deb2f6034e']" 
 phd="{&quot;action&quot;: &quot;enable&quot;, &quot;code&quot;: 3002}"
 phd-unit="Bank(Y)" class="btn action-btn" style="margin-left: 5px;" type="button" 
 ng-click="PackageManagementCtrl.downloadPackage('dde0fcb2-948b-4bbc-b347-40deb2f6034e',
 'Pack_110','topPackageTable1dde0fcb2-948b-4bbc-b347-40deb2f6034e')">
<i class="fa fa-download"></i>  Download</button>

Ini adalah ekspresi CSS yang saya berikan ke kode Selenium saya:

[phd-unit='Bank(Y)'][ng-click*='Pack_110'][ng-click*='downloadPackage']

Kode saya:

 @Test
public void findElementByCss() {

    softAsserter = new SoftAsserter(testParameters);
    String CssExpresion = testParameters.get("actionData");

    WebElement optionToFind = null;
    try {
        WebDriverWait wait = new WebDriverWait(browser, 5);
        optionToFind = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(CssExpresion)));
    }
    catch (Exception ex){
        softAsserter.fail(ex.getMessage());
    }
    if (optionToFind==null) {
        softAsserter.fail("failed to failed element with expression: " + CssExpresion);
    }
    if (optionToFind!=null) {
        softAsserter.assertTrue(true, "Element found by attributes: </br>" + CssExpresion);
    }
    if (softAsserter.isOneFailed()) {
        asserter.fail("findElementByCss failed");
    }
}

Mengapa kode saya gagal menemukan elemen khusus ini?

0
Tal Angel 15 Januari 2020, 17:51

2 jawaban

Jawaban Terbaik

Masalahnya adalah:

Kondisi yang Diharapkan.visibilityOfElementLocated

Mengubahnya menjadi:

ExpectedConditions.presenceOfElementLocated

Dan itu bekerja seperti pesona

0
Tal Angel 15 Januari 2020, 15:34

Saya akan menyarankan menggunakan pemilih css berikut.

button.btn.action-btn[title='Download package']

ATAU

button.btn.action-btn[title='Download package'][phd-unit='Bank(Y)']
2
KunduK 15 Januari 2020, 14:59