作者: bongbong3481 時間: 2023-10-25 06:59 標題: Python selenium send Enter 問題
用python selenium send_keys可以send 到文字,如果send_keys(Keys.ENTER) 就吾得,但改用send_keys(‘\ue007’) 就沒問題。
請問點解咁怪?
作者: s20012797 時間: 2023-10-25 09:32
In Python, the send_keys() method of the Selenium WebDriver class is used to send keyboard input to an element. The Keys class contains constants that represent different keyboard keys, such as Keys.ENTER for the Enter key.
When you use send_keys(Keys.ENTER), the WebDriver sends the Enter key event to the element. This is a standard keyboard event that is recognized by most web browsers.
However, when you use send_keys(‘\ue007’), the WebDriver sends a Unicode character with the code point U+E007. This character is not a standard keyboard key, and it is not recognized by most web browsers.
As a result, when you use send_keys(‘\ue007’), the WebDriver sends a character that is not recognized by the web browser. This can cause problems, such as the text not being entered into the element correctly.
To avoid this problem, you should use send_keys(Keys.ENTER) to send the Enter key event to the element. This will ensure that the text is entered into the element correctly.
作者: bongbong3481 時間: 2023-10-25 12:11
回覆 2# s20012797
我的情況剛好調轉,Keys.enter 用吾到
作者: abcjerry 時間: 2023-10-25 12:14
反爬虫吧
作者: s20012797 時間: 2023-10-25 12:20
If Keys.ENTER is not working, you can try the following:
Make sure that you are using the correct WebDriver instance.
Make sure that the element you are trying to send the Enter key to is in focus.
Try using the sendKeys() method instead of the send_keys() method.
Try using the executeScript() method to send the Enter key event to the element.
Here is an example of how to use the executeScript() method to send the Enter key event to an element:
driver = webdriver.Chrome()
driver.get("https://www.demo.com")
element = driver.find_element_by_name("q")
driver.execute_script("arguments[0].dispatchEvent(new KeyboardEvent('keydown', {'key': 'Enter'}))", element)
作者: bongbong3481 時間: 2023-10-25 19:00
回覆 4# abcjerry
不是爬蟲的,公司有個內部網頁,每個同事下面要入n個編號,要一個一個係excel 複製入個網頁,都好花時間,所以試下半自動用selenium 整。
作者: bongbong3481 時間: 2023-10-25 19:01
回覆 5# s20012797
得閑試試,thx
作者: 傑洛 時間: 2023-10-30 18:47
學下用 python send request
你公司個網填完一大堆嘢之後,其實就係將 data 放入 request 度 send 出去
作者: bongbong3481 時間: 2023-10-30 19:07
回覆 8# 傑洛
我以為爬蟲先咁玩,得閑研究下先, thx

