背景:
使用selenium driver api 不能對定位到的元素進行操作
解決方案
#向codeMirror代碼編輯器中填寫代碼,該xpath應為包含codemirror整體的類的xpath,不可以是各個細分codemirror組件的xpath
示例代碼
1 def demo(self, content): 2 3 # content:輸入的內容
4 5 elem = self.driver.find_element_by_xpath('//div[@class="CodeMirror cm-s-default CodeMirror-wrap"]')
6 # 第一個參數為固定的寫法,第二個參數是元素定位實例 7 self.driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);", elem, content)