簡體   English   中英

找不到xpath ==“ // * [text()[contains(。,'” + word +”')]]“的元素

[英]Unable to find element with xpath == “//*[text()[contains(.,' ”+ word + “ ')]]”

我曾將sapui5與xml視圖和java項目一起使用,並使用Selenium 1.82進行了自動化測試。

像這樣的xml代碼

<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:f="sap.ui.layout.form" xmlns:l="sap.ui.layout">
  <Panel expanded="true" expandable="true" width="auto">
    <headerToolbar>
      <Toolbar>
        <Title text="{i18n>POLICY_HOLDER_INFO_BASIC_INFO}" />
      </Toolbar>
    </headerToolbar>
    <content>
      <f:SimpleForm layout="ResponsiveGridLayout" labelSpanL="3" labelSpanM="3" labelSpanS="12" editable="true">
        <f:content>
            <VBox>
                <CheckBox id="SameWithInsured" text="{i18n>POLICY_HOLDER_INFO_SAME_WITH_INSURED}" groupName="holderstatus1" selected="{searchModel>/d/SamewithInsured}" select="changeSameWithInsured"/>
                <layoutData>
                    <l:GridData span="L12 M12 S12" indent="L3 M3 S3"></l:GridData>
                </layoutData>
            </VBox>
          <Label text="{i18n>POLICY_HOLDER_INFO_IDENTIFICATION}" />
          <VBox>
            <RadioButton id="PHPerson" text="{i18n>POLICY_HOLDER_INFO_INDIVIDUAL}" enabled="{ path: '/d/SamewithInsured', model: 'searchModel', formatter: '.isPHDEditEnabled'}" groupName="holderstatus" selected="{= ${searchModel>/d/Person}===true}" select="clearRelation"/>
          </VBox>
          <VBox>
            <RadioButton id="PHLegalEntity" text="{i18n>POLICY_HOLDER_INFO_CORPORATION}" enabled="{ path: '/d/SamewithInsured', model: 'searchModel', formatter: '.isLegalEntityEnabled'}" groupName="holderstatus" selected="{=${searchModel>/d/LegalEntity}===true}" select="clearRelation"/>
          </VBox>
          <Label text="{i18n>POLICY_HOLDER_INFO_RELATIONSHIP}"/>
          <Select id="relationSelect" width="100%" selectedKey="{searchModel>/d/RelationshipKey}" enabled="{ path: '/d/SamewithInsured', model: 'searchModel', formatter: '.isPHDEditEnabled'}" change="relationSelectChange">
            <items>
              <core:Item key="1" text="{i18n>POLICYHOLDER_BASICINFO_RELATION_BLANK}" />
              <core:Item key="2" text="{i18n>POLICYHOLDER_BASICINFO_RELATION_ELF}" enabled="{=${searchModel>/d/LegalEntity}===false}"/>
              <core:Item key="3" text="{i18n>POLICYHOLDER_BASICINFO_RELATION_SPOUSE}" enabled="{=${searchModel>/d/LegalEntity}===false}"/>
            </items>
          </Select>
        </f:content>
      </f:SimpleForm>
     </content>
  </Panel>
</core:FragmentDefinition>

我的測試腳本是(驅動程序已被實例化)

WebDriverWait wait = new WebDriverWait(driver,30);
WebElement e = wait.until(ExpectedConditions.elementToBeClickable(dirver.findElement(By.xpath("//*[text()[contains(.,'" + word + "')]]"))));
e.click;

我也試過

WebElement e = wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//core:FragmentDefinition/Panel/content/f:SimpleForm/f:content/Select/items/core:Item[contains(.,'" + word +"')]"))));

得到了org.openqa.selenium.InvalidSelectorException:無法使用xpath表達式定位元素// core:FragmentDefinition / Panel / content / f:SimpleForm / f:content / Select / items / core:Item [contains(。,'配偶')]由於以下錯誤:錯誤:未聲明命名空間前綴:核心有關此錯誤的文檔,請訪問: http : //seleniumhq.org/exceptions/invalid_selector_exception.html

您可以為xpath嘗試以下語法嗎?

"//*[contains(text(), '"+word+"')]"

我已經通過使用隱式等待而不是顯式等待來解決此問題。

driver.manage().timeouts().implicitlyWait(30 , TimeUnit.SECONDS);

暫無
暫無

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

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