元素当前不可见,因此可能无法与 [Firefox] 交互
Element is not currently visible and so may not be interacted with [Firefox]
我正在尝试单击名为 "Fast Path" 的按钮并输入 1067。但它抛出错误,例如 Element 当前不可见,因此可能无法与
这是 Chrome 的页面源代码,如果有帮助的话。
<span class="textUpperCase" style="position:relative;" id="pfx$txtFastPath-containerNode" onmouseout="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOut(event)" onmouseover="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOver(event)"><label id="pfx$txtFastPath-labelNode" for="pfx$txtFastPath">Fast Path :</label><input type="text" autocomplete="off" name="txtFastPath" class="textUpperCase focus focus" style="position:absolute;left:90px;top:0px;;text-align:left;margin:0px" size="12" id="pfx$txtFastPath" onblur="JKB.widget.manager.onHtmlBlur('pfx$txtFastPath',event)" onchange="JKB.widget.manager.getWidget('pfx$txtFastPath').onChange(event)" onfocus="JKB.widget.manager.onHtmlFocus('pfx$txtFastPath',event)" onkeydown="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyDown(event)" onkeyup="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyUp(event)" onkeypress="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyPress(event)" tabindex="0"></span>
编辑:更具可读性的版本(应该在语义上相同,但为了安全起见保留原始版本):
<span class="textUpperCase" style="position:relative;" id="pfx$txtFastPath-containerNode"
onmouseout="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOut(event)"
onmouseover="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOver(event)">
<label id="pfx$txtFastPath-labelNode" for="pfx$txtFastPath">Fast Path :</label>
<input type="text" autocomplete="off" name="txtFastPath"
class="textUpperCase focus focus"
style="position:absolute;left:90px;top:0px;;text-align:left;margin:0px"
size="12" id="pfx$txtFastPath"
onblur="JKB.widget.manager.onHtmlBlur('pfx$txtFastPath',event)"
onchange="JKB.widget.manager.getWidget('pfx$txtFastPath').onChange(event)"
onfocus="JKB.widget.manager.onHtmlFocus('pfx$txtFastPath',event)"
onkeydown="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyDown(event)"
onkeyup="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyUp(event)"
onkeypress="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyPress(event)"
tabindex="0">
</span>
不确定 python 语法,在 java 中,您可以通过回退到 JavaScript 驱动程序来单击不可见元素,例如js.executeScript("arguments[0].click();", element);
,这个解决方案的要点应该也适合你,只需将其写在 python
当我呈现提供的代码时,我没有看到可以点击的按钮,所以我只能在一般意义上描述您可能需要做什么。
首先,您可能需要告诉 WebDriver 等待给定时间或直到元素可见。这称为显式等待。 See the docs。这是一些示例代码:
element = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID,'name_of_id'))) # you can also use xpath or any of selenium's other find_by commands. [See here][2] for a list.
然后你只需要 click()
按钮。就这么简单
element.click()
就是这样。如果我误解了你的问题,请随时在评论中澄清。祝你好运!
我正在尝试单击名为 "Fast Path" 的按钮并输入 1067。但它抛出错误,例如 Element 当前不可见,因此可能无法与 这是 Chrome 的页面源代码,如果有帮助的话。
<span class="textUpperCase" style="position:relative;" id="pfx$txtFastPath-containerNode" onmouseout="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOut(event)" onmouseover="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOver(event)"><label id="pfx$txtFastPath-labelNode" for="pfx$txtFastPath">Fast Path :</label><input type="text" autocomplete="off" name="txtFastPath" class="textUpperCase focus focus" style="position:absolute;left:90px;top:0px;;text-align:left;margin:0px" size="12" id="pfx$txtFastPath" onblur="JKB.widget.manager.onHtmlBlur('pfx$txtFastPath',event)" onchange="JKB.widget.manager.getWidget('pfx$txtFastPath').onChange(event)" onfocus="JKB.widget.manager.onHtmlFocus('pfx$txtFastPath',event)" onkeydown="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyDown(event)" onkeyup="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyUp(event)" onkeypress="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyPress(event)" tabindex="0"></span>
编辑:更具可读性的版本(应该在语义上相同,但为了安全起见保留原始版本):
<span class="textUpperCase" style="position:relative;" id="pfx$txtFastPath-containerNode"
onmouseout="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOut(event)"
onmouseover="JKB.widget.manager.getWidget('pfx$txtFastPath').onMouseOver(event)">
<label id="pfx$txtFastPath-labelNode" for="pfx$txtFastPath">Fast Path :</label>
<input type="text" autocomplete="off" name="txtFastPath"
class="textUpperCase focus focus"
style="position:absolute;left:90px;top:0px;;text-align:left;margin:0px"
size="12" id="pfx$txtFastPath"
onblur="JKB.widget.manager.onHtmlBlur('pfx$txtFastPath',event)"
onchange="JKB.widget.manager.getWidget('pfx$txtFastPath').onChange(event)"
onfocus="JKB.widget.manager.onHtmlFocus('pfx$txtFastPath',event)"
onkeydown="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyDown(event)"
onkeyup="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyUp(event)"
onkeypress="JKB.widget.manager.getWidget('pfx$txtFastPath').onKeyPress(event)"
tabindex="0">
</span>
不确定 python 语法,在 java 中,您可以通过回退到 JavaScript 驱动程序来单击不可见元素,例如js.executeScript("arguments[0].click();", element);
,这个解决方案的要点应该也适合你,只需将其写在 python
当我呈现提供的代码时,我没有看到可以点击的按钮,所以我只能在一般意义上描述您可能需要做什么。
首先,您可能需要告诉 WebDriver 等待给定时间或直到元素可见。这称为显式等待。 See the docs。这是一些示例代码:
element = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID,'name_of_id'))) # you can also use xpath or any of selenium's other find_by commands. [See here][2] for a list.
然后你只需要 click()
按钮。就这么简单
element.click()
就是这样。如果我误解了你的问题,请随时在评论中澄清。祝你好运!