下面是我试图获得xpath的HTML片段。我在chrome开发工具中尝试了这么多的组合,但是没有运气。Chropath消息是该元素可能来自不同的src。我不知道这是什么意思。任何帮助都很感激。
<input type="text" class="sn-global-typeahead-input -global-active-input" name="sncwsgs-
typeahead-input" id="sncwsgs-typeahead-input" placeholder="Search Global" autocomplete="off"
aria-label="Search" aria-hidden="false" aria-expanded="true" aria-activedescendant="sncwsgs-
typeahead-record-1-2" aria-autocomplete="both" aria-owns="sncwsgs-typeahead-sections" aria-
controls="sncwsgs-typeahead-sections" aria-describedby="sncwsgs-typeahead-instructions" aria-
haspopup="listbox" value="" role="combobox">
发布于 2022-09-28 03:40:10
有一个id
标记,所以您可以在XPath中使用以下内容:
"//input[@id='sncwsgs-typeahead-input']"
这也转化为以下CSS选择器:
"input#sncwsgs-typeahead-input"
但是,如果这是在iframe
中,则需要先切换到iframe,然后才能与其中的元素交互。
在这里了解如何切换到iframes:https://www.selenium.dev/documentation/webdriver/interactions/frames/
切换到iframe
的示例
driver.switch_to.frame("iframe")
https://stackoverflow.com/questions/73874150
复制相似问题