【发布时间】:2019-07-06 11:17:14
【问题描述】:
我正在编写一个 selenium 脚本来识别元素并将密钥发送给它以用于 SAP 接口。
这适用于 SAP Fiori UI 应用程序。
即使我在 chrome 中运行代码时识别的 xpath 是唯一的,但它不能识别元素。
下面是我的代码:
public static void main(String[] args) {
// declaration and instantiation of objects/variables
String baseURL = "https://mercury.abc.net/default.aspx";
WebDriver driver;
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\abcde\\Desktop\\Eclipse\\Selenium
Practice\\libs\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
driver = new ChromeDriver(options);
// launch Chrome and direct it to the Base URL
driver.get(baseURL);
WebElement MyTimesheetButton =
driver.findElement(By.id("Tile_WPQ8_8_7"));
MyTimesheetButton.click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*
[@id=\"WD027B\"]")));
WebElement Engagement =
driver.findElement(By.xpath("//[@id=\"WD027B\"]"));
Engagement.sendKeys("test");
//close Chrome
driver.close();
}
我应该得到预期的结果作为元素识别和数据键入元素,但我得到的实际结果如下:
Cannot locate an element using By.xpath: //*[@id="WD027B"]
HTML:
<iframe role="main" frameborder="0" title="The title of the hosted application within the canvas area: My Timesheet" '="" src="/nwbc/ZEP3_FIN_TM_ENTRY_DYNPRO_MSTR/?sap-client=200&sap-language=EN&sap-nwbc-node=page_collection&sap-nwbc-version_hash=392D742742D08304E969040C8A992A95&sap-theme=zcorbu" id="iFrameId_1550067729776" name="iFrameId_1550067729776" style="display: block; width: 1036px; height: 641px;">Your browser is currently configured not to display inline 
<table id="WD027B-r" class="lsTblEdf3Whl lsField--table"> <tbody> <tr> <td class="lsTblEdf3Td urBorderBox" style="vertical-align:top;"><input id="WD027B" ct="CBS" lsdata="{0:'WD027B',5:'FREETEXT',7:'WD027C',14:true,20:40,25:'CLIENT_SERVER_PREFIX',26:'F4LOOKUP',30:true,32:40,34:true,35:'VALUE1'}" class="lsTblEdf3 urBorderBox urEdf2TxtHv" value="" role="combobox" name="WD027B" style="vertical-align:top;"> </td> </tr> </tbody> </table>
</iframe>
【问题讨论】:
-
以上代码 sn-p 中没有的任何具体内容?
-
我的意思是您提供的 ID 看起来像是一个随机值。您可以尝试使用其他属性吗。但这就是我要求提供 html 的原因。以便 OP 可以识别您无法 ATM .
-
您的“表格”元素是否在框架/iframe 元素中?
-
是的,它在 iframe 内
标签: selenium xpath css-selectors webdriver webdriverwait