Seleniumで
input_element
には入れたい要素
input_element.send_keys(value)
この方法だとvalue
に絵文字があると失敗した
Chromedriver only supports characters in the BMP
このエラーが邪魔!
teratailにこんなやり方がある でも任意の文字を入れるのはなんか嫌だ。あとでバックスペースもいけるかも? Seleniumでtextareaに絵文字入りのテキストをReturnキーで送信できません。
こっちのやり方。 https://stackoverflow.com/questions/59138825/chromedriver-only-supports-characters-in-the-bmp-error-while-sending-emoji-with answered Aug 18, 2022 at 13:06 の Zahouani Mouradさんの方法。
js_code = """ var elm = arguments[0], txt = arguments[1]; elm.value += txt; elm.dispatchEvent(new Event('change')); """
でJSのヒアドキュメントを用意して
driver.execute_script(js_code, input_element, value)
input_element
には入れたい要素
value
は実際入れたい値。
これで行けた。