[英]Unable to find element with xpath == “//*[text()[contains(.,' ”+ word + “ ')]]”
I had used sapui5 with xml view and java project, using Selenium 1.82 for automated testing. 我曾将sapui5与xml视图和java项目一起使用,并使用Selenium 1.82进行了自动化测试。
xml code like this 像这样的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>
My test script is(driver have been instanced) 我的测试脚本是(驱动程序已被实例化)
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement e = wait.until(ExpectedConditions.elementToBeClickable(dirver.findElement(By.xpath("//*[text()[contains(.,'" + word + "')]]"))));
e.click;
I also tried 我也试过
WebElement e = wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//core:FragmentDefinition/Panel/content/f:SimpleForm/f:content/Select/items/core:Item[contains(.,'" + word +"')]"))));
got org.openqa.selenium.InvalidSelectorException: Unable to locate an element with the xpath expression //core:FragmentDefinition/Panel/content/f:SimpleForm/f:content/Select/items/core:Item[contains(.,'配偶')] because of the following error: Error: Namespace prefix not declared: core For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html 得到了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.