我正在使用 selenium 来填写网络表单,但由于某种原因这个特定的文本框给我带来了麻烦。它的 html 是:
<input type="text" class="black_ar" value="" size="25" id="type" name="type"
onmouseover="showTip(this.id)" onmouseout="hideTip(this.id)"
onblur="trimByAutoTag(this);onSubTypeChangeUnit('className',this,'unitSpan')"
autocomplete="off" title="">
我用过:
driver.find_element_by_name('type').click()
和
driver.find_element_by_xpath('xpath').click()
但是他们都说找不到该元素。我不确定它是否在 iframe 中(如果有人知道检查方法),并且正在使用 chropath,它是一个 chrome 扩展来查找元素的 xpath。
编辑:chropath 在相对 xpath 下说“它可能是 svg/pseudo/comment/iframe 的子项。XPath 不支持它们。”如果有帮助的话
最佳答案
根据您共享的在文本框中单击的HTML,您可以使用以下任一解决方案:
xpath
:driver.find_element_by_xpath("//input[@class='black_ar' and @id='type']").click()
css_selector
:driver.find_element_by_css_selector("input.black_ar#type").click()
关于python - 如何根据 Selenium、Python 和 Xpath 提供的 html 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51994821/