[英]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.