-1
<textarea style="font-size: 1.2em" ng-model="applications" ng-list=" " ng-trim="false" rows="15" cols="70" class="ng-valid ng-dirty ng-valid-parse ng-touched"></textarea>

This is the text area tag. I want to insert some text into the text area. How can I proceed with the python code for the selenium webdriver.

I tried:

driver.find_element_by_class_name("ng-pristine ng-valid ng-touched")

Please help me out.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Finding an element using angular tags can be a bit flaky. I think the classes like ng-pristine will be removed once the field has changed. A better approach would be to find the field using parent or sibling elements. Also if there is only 1 texteara, you can try: find_element_by_tag_name('textarea') – Greg Dec 19 '20 at 12:55

2 Answers2

0
 driver.find_element_by_class_name("ng-pristine.ng-valid.ng-touched"). 

Or

 driver.find_element_by_xpath("//textarea[@claaa='ng-pristine ng-valid ng-touched']")

Class with space indicates multiple classes , so you have to replace space with dot in find_element_by_class

Else use xpath and find the element that matches absolute attribute value of the class

PDHide
  • 10,919
  • 2
  • 12
  • 26
0

To send a character sequence to the element you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("textarea.ng-valid.ng-dirty.ng-valid-parse.ng-touched[ng-model='applications']").send_keys("samhith gardas")
    
  • Using xpath:

    driver.find_element_by_xpath("//textarea[@class='ng-valid ng-dirty ng-valid-parse ng-touched' and @ng-model='applications']").send_keys("samhith gardas")
    

However the desired element is a Angular element, so ideally to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.ng-valid.ng-dirty.ng-valid-parse.ng-touched[ng-model='applications']"))).send_keys("samhith gardas")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@class='ng-valid ng-dirty ng-valid-parse ng-touched' and @ng-model='applications']"))).send_keys("samhith gardas")
    
  • 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
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217