Entering text to span Selenium/Python

一曲冷凌霜 提交于 2021-01-28 04:10:21

问题


I try to enter text to span in place of "SAMPLE TEXT". I'm using Selenium/Python but I can't do it using send_keys method. Do you have any other ideas how can I do that? I attached screenshots with HTML and screenshot from app

I tried to use that code, but doesnt work:

body = driver.find_element_by_xpath('//*[@id="oss-view-wrapper"]/main/div/div/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div/div/div[6]/div[1]/div/div/div/div[5]/div/pre/span')
body.send_keys("TEST")

回答1:


You can use javasecriptExceutor for that, Please chech code at once i am not have deep knowledge of Python:

element = driver.find_element_by_xpath('Your xpath')
driver.execute_script("arguments[0].innerText = 'test'", element)


来源:https://stackoverflow.com/questions/47136239/entering-text-to-span-selenium-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!