How to modify the innerHTML of a contenteditable element

前端 未结 1 1045
忘掉有多难
忘掉有多难 2020-12-22 11:42

I\'m using Selenium with Chrome-driver and python3.6 to test a website. I have code snippet in the webpage as follow:

相关标签:
1条回答
  • 2020-12-22 12:10

    To replace the text ******* with the text Hello World! as the element is a React element you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

    • Using CSS_SELECTOR:

      element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.copyable-text.selectable-text[data-tab='1']")))
      element.click()
      element.clear()
      element.send_keys("Hello World!")
      
    • Using XPATH:

      element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'selectable-text')][contains(.,'*******')]")))
      element.click()
      element.clear()
      element.send_keys("Hello World!")
      
    • Note: You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      
    0 讨论(0)
提交回复
热议问题