修复使用Python的硒形式的等待时间
我是Python的新手,并且正在尝试自动化一个表格。我已经完成了所有工作,但是当试图“提交”时,它没有读取XPath,因此没有单击。
html:
<input style="text-align: center; height: 24px;" onclick="return (Button.OnClick(this, event));" onfocus="return (Button.OnFocus(this, event));" id="FormControl_V1_I1_B12" scriptclass="Button" class="t_cP1RLqWVMhs644yI_0 bg_cP1RLqWVMhs644yI_0 a4_cP1RLqWVMhs644yI_0" wrapped="true" direction="ltr" viewdatanode="13" formid="FormControl" originalid="V1_I1_B12" tabindex="0" title="" buttonid="CTRL10_5" value="Submit" type="button">
这是python代码(第二代码处理OK弹出窗口):
click_value = web.find_element(By.XPATH('//*[@id="FormControl_V1_I1_B12"]')).get_attribute("onclick")
print(click_value)
web.switch_to.alert.accept()
element快照:
此处html标签:
I'm new to Python and am trying to automate a form fill up. I have done all the work but when trying to "Submit" it's not reading the XPATH and hence not clicking.
HTML:
<input style="text-align: center; height: 24px;" onclick="return (Button.OnClick(this, event));" onfocus="return (Button.OnFocus(this, event));" id="FormControl_V1_I1_B12" scriptclass="Button" class="t_cP1RLqWVMhs644yI_0 bg_cP1RLqWVMhs644yI_0 a4_cP1RLqWVMhs644yI_0" wrapped="true" direction="ltr" viewdatanode="13" formid="FormControl" originalid="V1_I1_B12" tabindex="0" title="" buttonid="CTRL10_5" value="Submit" type="button">
Here is the Python Code (the 2nd code handles the Ok popup):
click_value = web.find_element(By.XPATH('//*[@id="FormControl_V1_I1_B12"]')).get_attribute("onclick")
print(click_value)
web.switch_to.alert.accept()
Element snapshot:
Here is the HTML tag:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要单击元素,您需要诱导 webdriverwait element_to_be_clickable() ,您可以使用以下任何一个 >定位器策略 :
使用 css_selector :
使用 xpath :
注意:您必须添加以下导入:
To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
Using XPATH:
Note: You have to add the following imports :