每次在选择实时更新字段时请求标识发生更改。无法使用xpath查找实时更新字段的元素
正尝试通过的XPath
这让请求ID是源代码。
<form id="itemscreen334-33504-" class="itemscreen addMode v_334 ajaxForm form-initialized" method="POST" enctype="multipart/form-data" requestid="18310" style="visibility: visible; opacity: 1;">
Java代码:
WebElement form = driver.findElement(By.xpath("//form[Class='itemscreen addMode v_334 ajaxForm form-initialized')]"));
System.out.println("form-->" + form);
String requestNo = form.getAttribute("requestid");
System.out.println("requestNo----------->" + requestNo);
硒错误:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector //form[Class='itemscreen addMode v_334 ajaxForm form-initialized')] is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //form[Class='itemscreen addMode v_334 ajaxForm form-initialized')] because of the following error: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: ""]
?我怎样才能使用XPath请求ID?
XPath中的一个问题是,你有'form [Class'而不是'form [@ class',但你最好使用CSS选择器,如下面的答案。它更灵活。 – JeffC