簡體   English   中英

在selenium python webdriver中使用send_keys()發送三個鍵

[英]To send threekeys using send_keys() in selenium python webdriver

我試圖在默認值為0.00的文本框中鍵入一個浮點數。但是它嘗試獲取附加而不是覆蓋它。我嘗試使用.clear()然后發送send_keys('123.00'),但它仍然會被追加。 然后我嘗試使用send_keys(Keys.CONTROL +'a','123.00')。它僅更新0.00。

任何幫助都非常感謝。

有關詳細信息.. URL: http ://new.ossmoketest.appspot.com userid:senthil.arumugam@mycompanyname.com - mycompanyname = orangescape(對不起,以避免垃圾郵件)密碼現在不需要。 點擊購買訂單...在形式請新產品和新價格...自動化的樣品申請..謝謝

我得到了很好的結果:

from selenium.webdriver.common.keys import Keys

element.send_keys(Keys.CONTROL, 'a')
element.send_keys('123.00')

如果這不起作用,則可能與網頁中的代碼有關。

除非您有自定義編輯框,否則click()應該適合您:

from selenium.webdriver import Firefox

b = Firefox()
b.get('http://google.com')
e = b.find_element_by_id('lst-ib')

e.click()  # is optional, but makes sure the focus is on editbox.
e.send_keys('12.34')
e.get_attribute('value')
# outputs: u'12.34'

e.click()
e.clear()
e.get_attribute('value')
# outputs: u''

e.send_keys('56.78')
e.get_attribute('value')
# outputs: u'56.78'

我剛剛找到了clear()命令 - 請看這里

如果此元素是文本輸入元素,則將清除該值。 對其他元素沒有影響。 文本輸入元素是INPUT和TEXTAREA元素。

編輯:所以你的方法是:

   element.clear();
   element.sendKeys('123.00');

我遇到了其他答案中給出的所有例子的問題。

el.send_keys(Keys.CONTROL + 'a' + Keys.NULL, 'your string')

曾參與過我所參與的所有項目,所以我把它包裝到我自己的Webdriver類實現中,運行更強大。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM