无法将\u键发送到工具提示覆盖的webelement

2024-10-03 17:20:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试将价格填充到输入元素。 我试过很多方法,但都失败了,我意识到它可能被另一个元素所覆盖。 当我将鼠标指向该字段时,它会自动显示工具提示。我还看到一些HTML代码行出现在检查框中。你知道吗

图1:当我没有将鼠标指向该字段时,我的屏幕。你知道吗

i

图2:当我移动鼠标指向那个区域时,我的屏幕

i

以下是我的一些尝试:

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
driver.execute_script('arguments[0].innerHTML = "100000";', price)

结果:什么都不做,没有错误

或者

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
browserdriver.execute_script("$(arguments[0]).click();", price)
price.send_keys("10000")

或者

price=WebDriverWait(browserdriver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[@id='inputProductPrice']")))
price.click()
price.send_keys("10000")

或者

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
price.click()
price.send_keys("10000")

或者

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
actions.move_to_element(price).click(price).perform()
price.send_keys("10000")

我确信XPath是正确的,并且元素在屏幕上,因为我可以将\u键发送到该行中的类似字段(图1中带有蓝色突出显示框的名为“2”的字段)。你知道吗

html格式:

<div class="col-md-2">
                            <input type="text" class="form-control" placeholder="Nhập giá" id="inputProductPrice" title="" data-toggle="tooltip" data-original-title="(Trên 8.000 VNĐ)" data-bind="moneyMask: ProductPriceForAll">
                        </div>

请帮我克服这个限制。谢谢

补充的话:这个领域上面的一些领域也有一些工具提示结构,但我可以很容易地和成功地填写上述一些解决方案。但我不知道为什么这个领域成为一个强大的约束。例如,此字段(蓝色突出显示框): picture 3


Tags: sendid元素by屏幕element鼠标keys
2条回答

您应该尝试使用^{}^{}

action = ActionChains(browserdriver)
price = WebDriverWait(browserdriver, 10).until(EC.element_to_be_clickable((By.XPATH,"//input[@id='inputProductPrice']")))
action.move_to_element_with_offset(price, 5, 5)
action.click().perform()

你可以用偏移量来找到可以点击的区域。。。你知道吗

希望这对你有帮助!你知道吗

我不知道为什么send_keys("100000")不是工作。但是如果您使用的是JS executor,请尝试更新placeholdervalue属性。你知道吗

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
browserdriver.execute_script('arguments[0].placeholder = "100000";', price)

或者

price=browserdriver.find_element_by_xpath("//*[@id='inputProductPrice']")
browserdriver.execute_script('arguments[0].value = "100000";', price)

相关问题 更多 >