【发布时间】:2021-06-28 18:19:38
【问题描述】:
当我使用检查元素打开时,我看到如下代码:
<div spellcheck="false" unselectable="off" class="appmagic-label-text" data-control-part="text" data-bind="{
inlineEditText: properties.Text,
css: {
'appmagic-label-single-line': !properties.Wrap()
},
attr: {
'aria-live': live,
'aria-atomic': live() ? 'true' : null
}
}">Atostogų prašymai</div>
我正在尝试获取此文本“atostogų prašymai”xpath,但我无法找到它。
我尝试过的选项:
By.cssSelector("div[class='appmagic-label-text']");- 刚刚复制了 xpath
By.cssSelector("div[class='//*[@id=\"publishedCanvas\"]/div/div[2]/div/div/div[5]/div/div/div/div/div']");
iframe 代码可见:
<iframe class="publishedAppIframe" tabindex="0" aria-hidden="false" id="fullscreen-app-host" scrolling="no" frameborder="0" name="fullscreen-app-host" src="https://pa-content.azureedge.net/resource/webplayerdynamic/publishedapp/preloadindex?preloadIndexPath=https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%2Fupuvepsd66qk3%2Fpreloadindex.web.html&PowerAppsLanguage=en-US&loader=inline&lv=jpigefv5ue8uc&serviceWorkerUrl=https%3A%2F%2Fpa-content.azureedge.net%2Fresource%2Fwebplayer%2Fhashedresources%2Fqqhtjvhh4omr6%2Fjs%2FPowerAppsServiceWorker.PublishedApp.js&piv=796D32DE&featureGates={"publishedAppServiceWorker":false}#%7B%22platform%22%3A%22notwindows%22%2C%22hideNavBar%22%3A%22true%22%2C%22antiCSRFToken%22%3A%22f01dae6c-0d74-4f48-8a74-95b9ee3d5943%22%2C%22cdnUrl%22%3A%22https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%22%2C%22paramsQuery%22%3A%22tenantId%3Dde6e25a9-36c4-424d-af6b-431db29f6cfe%26appId%3D%2Fproviders%2FMicrosoft.PowerApps%2Fapps%2Fff261fd6-5458-4a3f-8697-f50ff8a1ff06%22%2C%22iframeMode%22%3Anull%2C%22packagePropertiesVersion%22%3A%222.1%22%2C%22staticContentProxy%22%3A%22https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fwebplayerdynamic%2Fproxy%2Fstaticcontent%3FstaticContentPath%3D%22%2C%22launchFunctionUrlFormat%22%3A%22https%3A%2F%2Fapps.powerapps.com%2Fplay%2F%7B0%7D%22%2C%22region%22%3A%22prod%22%2C%22staticContentUrl%22%3A%22https%3A%2F%2Fstatic.powerapps.com%22%7D" allow="geolocation; microphone; camera; fullscreen" style="" title="Atostogos"></iframe>
我认为有一些与 iframe 相关的方法:
public void selectIframe() {
String parent = driver.getWindowHandle();
for (String childHandle : driver.getWindowHandles()) {
if (!childHandle.equals(parent)) {
driver.switchTo().frame(childHandle);
}
}
}
public void selectParentFrame() {
driver.switchTo().parentFrame();
}
在这种情况下我该如何使用它们?
【问题讨论】:
-
看起来您应该能够仅通过其类来选择它:
By.cssSelector(".appmagic-label-text")关于您的 XPath 尝试,您不能在字符串中使用 XPath 表达式,但如果您删除它可能会起作用开始和结束's。为什么您的 XPath 尝试比您的 CSS 尝试复杂得多?
标签: java selenium xpath css-selectors webdriver