Невозможно полностью ввести значения в текстовое поле с помощью клавиш отправки. Введены только частичные значения, ошибки не показаны - PullRequest
1 голос
/ 03 августа 2020

Невозможно полностью ввести значения в поле текстового поля с помощью клавиш отправки. Введены только частичные значения, ошибки не показаны.

Попытка отправить ключи с ожиданием. Попытка отправить ключи медленно.

[Edit] - это весь скрипт, как указано в комментариях ниже

from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
import time
from time import sleep
from selenium.webdriver.common.keys import 

Keysdriver=webdriver.Chrome(executable_path="C:\Program Files (x86)\Drivers\chromedriver.exe")

driver.get("https://www.volunteers.ae/register.aspx")


driver.find_element_by_xpath("//*[@id='topnav_btnLangShift']").click()

driver.find_element(By.ID,'body_txtFName').send_keys("RADHIKA")

driver.find_element(By.ID,'body_txtLName').send_keys("PORANKI")

driver.find_element_by_id("body_txtEmail").send_keys("radhika.po@gmail.com")
element=driver.find_element_by_id("body_ddGender")
dropdown=Select(element)dropdown.select_by_value("Female")
driver.find_element_by_id("ctl00_body_txtDOB_dateInput").send_keys("08/04/1986")
element=driver.find_element_by_id("body_ddNationality")
dropdown=Select(element)
dropdown.select_by_value("India")
element=driver.find_element_by_id("body_ddCountryOfResidence")
dropdown=Select(element)
dropdown.select_by_value("+971")
element=driver.find_element_by_id("body_ddEmirate")
dropdown=Select(element)
dropdown.select_by_value("DUBAI")
time.sleep(10)

element=driver.find_element_by_id("body_ddCity")

dropdown=Select(element)

dropdown.select_by_value("DUBAI CITY")

def ClickAndSlowType(element, text):
    element.click()
    sleep(1) # let scripts run
    for t in list(text):
        print(t)
        element.send_keys(t)
        sleep (0.1)

mobile = WebDriverWait(driver, 8).until(ec.element_to_be_clickable((By.XPATH, "//*[@id='ctl00_body_txtEtisalat']")))
mobile.click()
mobile.send_keys("68862632")

1 Ответ

0 голосов
/ 04 августа 2020

В чем проблема при запуске вашего скрипта?

Я улучшил ваш скрипт с помощью действия ожидания, и он отлично работает:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.volunteers.ae/register.aspx')

mobile = WebDriverWait(driver, 8).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='ctl00_body_txtEtisalat']")))
mobile.click()
mobile.send_keys("68862632")

Результат выглядит так:

enter image description here

There does seem to be some scripting at work in the page. Evertyime you click and type it resents the field. However, the above code still seems to work.

If there's a problem, let me know what's happening (with any relevant errors that occur) and i'll look again.


[Update!]

Based on the comments below, try typing with a delay. Add this import:

from time import sleep

Add this function:

def ClickAndSlowType(element, text):
    element.click()
    sleep(1) # let scripts run
    for t in list(text):
        print(t)
        element.send_keys(t)
        sleep (0.1)

Run this:

mobile = WebDriverWait(driver, 8).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='ctl00_body_txtEtisalat']")))
ClickAndSlowType(mobile, "68862632")

I can't recreate your issue but this also works for me so worth a try. It just types a bit slower in case of the funky in-page script issues.

Let me know how it goes.

If you can update your question with your entire i code i might be able to recreate and provide a tried and tested answer. (no one likes "it worked for me")


As it works locally but not on @Paul 's machine : we need to debug it . Try this at the end of the script and please tell exactly what you see happen to the field and what the output from the prints on the console:


def WaitForDocumentReadyState():
    print("Ready State Before: " + driver.execute_script('return document.readyState'))
    WebDriverWait(driver, 10).until(lambda driver: driver.execute_script('return document.readyState') == 'complete')


def ClickAndSlowType(element, text):
    element.click()
    WaitForDocumentReadyState()
    sleep(1) # let scripts run
    for t in list(text):
        element.send_keys(t)
        WaitForDocumentReadyState()
        sleep (0.5)
    sleep(1) # let scripts run
    WaitForDocumentReadyState()    


mobile = WebDriverWait(driver, 8).until(ec.element_to_be_clickable((By.XPATH, "//*[@id='ctl00_body_txtEtisalat']")))
#mobile.click()## REMOVED
#mobile.send_keys("68862632") ## REMOVED
ClickAndSlowType(mobile, "68862632")  ## using the function
...