简体   繁体   English

Python Selenium,我无法填写此输入字段,密钥已发送且可见,但在我执行其他操作后它们消失了

[英]Python Selenium, I can't fill this input field, keys are sent and visible, but they're gone after I do something else

so I have a website to enter new products.所以我有一个网站可以输入新产品。

When I open that input from my browser, no problem it just works fine.当我从浏览器打开该输入时,没问题,它工作正常。

But when I open that with selenium browser, I can send_keys(), but can't do more.但是当我用 selenium 浏览器打开它时,我可以 send_keys(),但不能做更多。 I know I couldn't explain it, but you will definitely understand my problem when you see the video.我知道我无法解释,但是当您看到视频时,您肯定会理解我的问题。

Video of that input type: https://youtu.be/2ZqKzxeULyk 10 seconds该输入类型的视频: https://youtu.be/2ZqKzxeULyk 10 秒

Video of the problem part: https://youtu.be/MTTn8RBwa40 10 seconds问题部分视频: https://youtu.be/MTTn8RBwa40 10秒

I've tried pressing enter once, twice and clicking the input我试过按回车一次,两次然后点击输入

code used in the video:视频中使用的代码:

self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input") ## CLICK ON INPUT
self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(color)
self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(Keys.ENTER)

This also did not work这也不起作用

self.driver.execute_script("arguments[0].click()",(self.driver.find_element_by_xpath("/html/body/span[5]/span/span/ul/li")))

Edit: solved the problem by clicking the dropdown list item with element.click() thanks for help编辑:通过单击带有 element.click() 的下拉列表项解决了问题,感谢您的帮助

self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(color,Keys.ENTER)

could you try the below xpath, i think when you send keys to field separately it replaces the enitre content in that input field, so if you wnat to type somehting and then press enter you have to do it as "string"+key你能试试下面的 xpath,我认为当你将键单独发送到字段时,它会替换该输入字段中的全部内容,所以如果你想输入一些内容然后按 Enter,你必须将其作为“字符串”+键

self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(color,Keys.ENTER)

or或者

self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(color+Keys.ENTER)

or或者

self.driver.find_element_by_xpath("//*[@id='product_attributes']/div[2]/div[1]/div/table/tbody/tr[1]/td[2]/span/span[1]/span/ul/li/input").send_keys(color,Keys.TAB)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium 无法填写输入字段 - Python Selenium can't fill input field Python / Selenium,如果“无法访问此站点”,则执行其他操作 - Python / Selenium, if 'This site can’t be reached' then do something else 如何使用 Selenium 来等待一个元素在页面上可见(然后转到其他内容)? - How can I use Selenium to wait for an element to be visible on a page (but then move on to something else)? 蟒蛇游戏; 为什么我不能重新调用我的输入和 if/else 函数? - Python game; Why can't I re-call my input and if/else function? Selenium可识别输入字段,但未发送键 - Input Field is Recognized by Selenium but Keys are not Being Sent Selenium Python 按下按钮后,一个新的 window 打开,我无法按下那里的键 - Selenium Python After pressing the button,a new window opens,I can't press the keys there 我无法在 selenium python 中填写卡片数据 - I can't fill card data in selenium python 如果用户的输入低于 18,我如何让 python 对用户的输入做出回应? 18岁以上还有什么? - How can I make python say something in response to the users input if their input is below 18? And something else if it is above 18? python selenium无法清除输入字段 - python selenium can't clear input field 如何使输入与其他内容打印在同一打印件中? - How do I make an input to be printed in the same print as something else?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM