Josh Miller
Josh Miller

Reputation: 19

Python Send Keys Function In Selenium

I m trying to send keys using selenium by send keys function to fill some data but unfortunately code is not working.Here is HTML CODE where i want to fill some data and Python selenium code below.What can be the problem in my code

<input type="text" style="margin-bottom:16px" value="My New Sketch" autocomplete="on" maxlength="60" minlenght="2" required="required" class="required" tabindex="1" name="title">

browser.find_element_by_css_selector(".required").send_keys(Keys.BACKSPACE)
    time.sleep(5)
    browser.find_element_by_css_selector(".required").send_keys("UserName");
    time.sleep(8)

Upvotes: 0

Views: 1212

Answers (1)

murali selenium
murali selenium

Reputation: 3927

I am not sure why back space is used here but to clear input fields can use clear, in java

 driver.findElement(By.cssSelector(".required")).clear();

if sendkeys does not works, some time initial click then sendkeys work well

    driver.findElement(By.cssSelector(".required")).click();
    driver.findElement(By.cssSelector(".required")).sendKeys("data here");

I hope required wait is provided.

Thank You, Murali

Upvotes: 1

Related Questions