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.

1
  • 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') Commented Dec 19, 2020 at 12:55

2 Answers 2

1

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
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Debanjan B;. Will try and let you know.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.