如何执行点击字符串值?

时间:2019-01-30 05:47:00

标签: selenium selenium-webdriver

我想单击存储在字符串中的变量值,下面是我的代码。

OrderConfirmationData orderConfirmationData= (OrderConfirmationData)Serenity.sessionVariableCalled("OrderConfirmationData");
        int maxtries=0;

        System.out.println("Order is available in NTI" + EfloristConstants.lastname.get());

        List<WebElement> recordcount = getDriver().findElements(By.xpath("//table[contains(@id,'ctrlDWController1_DWDetails1_gvNTI')]/*/tr[not(contains(@style,'bold'))]"));
        int j=16;
        for(int i=1;i<=recordcount.size();i++) {
            j=j*i;
            String record = "(//table[contains(@id,'ctrlDWController1_DWDetails1_gvNTI')]/*/tr[not(contains(@style,'bold'))]/td)["+j+"]";
            String recipientname= element(By.xpath(record)).getTextValue();

            if(recipientname.equals(orderConfirmationData.getShipFirstName() != null)) {
                System.out.println("Order is available ");  
            }
            j=16;
        }

想要在条件满足时单击收件人名称,即要在“条件”条件内单击。

1 个答案:

答案 0 :(得分:1)

在满足条件的情况下添加以下行:

element(By.xpath(record)).click()