Python Selenium : for x in [List] : send_keys(x) looses Characters

Viewed 26

please help correcting my workflow:

I click on Search Button , now a Search Widget pops up. Input Field is already pre-selected.

I press CTRL+A and insert element [x] from my List.

Now are two possibilities.

A) I get a result and click the first result

B) after 5s have passed and the Widget is still loading, I press Enter and force it to load 1st Result

1st cycle works correctly, next cycles start producing Inputs with the first character of element x being cut off .

When clicking on a search result , the next cycle seems to repeat correctly , after concluding a cycle with enter , it produces a cut off character and kinda breaks all following cycles.

it seems, action.send_keys(Keys.ENTER).perform() causes the previous action command to repeat and also re-iterates through the complete appended list before stopping at the newest x element and inserting it ...

List = ["TEXT:One", "TEXT:Two", "TEXT:Three"]

for x in List:
    time.sleep(3)
    driver.find_element_by_xpath("//*[@id='path']").click()
    time.sleep(1)
    action.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).send_keys(x).perform()
    time.sleep(1)
    try:
        search_result = WebDriverWait(driver, 5, 1).until(EC.element_to_be_clickable((By.XPATH,"//path]")))
    except TimeoutException:
        search_result = False
    if search_result == True:
        driver.find_element_by_xpath("//path___").click()
    else:
        action.send_keys(Keys.ENTER).perform()
0 Answers
Related