我使用了sapui5和xml视图以及java项目,使用Selenium 1.82进行自动化测试。
像这样的<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(。 ,&#39;配偶&#39;)],因为以下错误: 错误:未声明命名空间前缀:core 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/invalid_selector_exception.html
答案 0 :(得分:2)
您可以为xpath尝试以下语法吗?
"//*[contains(text(), '"+word+"')]"
答案 1 :(得分:0)
我已经通过使用隐式等待而非显式等待来解决此问题。
driver.manage().timeouts().implicitlyWait(30 , TimeUnit.SECONDS);