Shreya Agarwal
Shreya Agarwal

Reputation: 716

Unable to enter value to input box with 'OnKeyPress' attribute - Selenium Python

I want my code to enter value in the box below and move to the next page. I'm using selenium in Python to do this.

enter image description here

This is the HTML for the element.

<input name="ctl00$SPWebPartManager1$g_d6877ff2_42a8_4804_8802_6d49230dae8a$ctl00$txtPageNumber" type="text" value="260" maxlength="5" 
onchange="return ValidateNumber(this);setTimeout('__doPostBack(\'ctl00$SPWebPartManager1$g_d6877ff2_42a8_4804_8802_6d49230dae8a$ctl00$txtPageNumber\',\'\')', 0)" 
onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) 
return false;javascript:return isNumber(event);" id="ctl00_SPWebPartManager1_g_d6877ff2_42a8_4804_8802_6d49230dae8a_ctl00_txtPageNumber" 
onpaste="return false;" style="width:60px;">

This is my code. How should get this to perform 'onkeypress' function?:

for i in range (2,10307):  #looping over the page numbers
       wait.until(EC.presence_of_element_located((By.ID, "ctl00_SPWebPartManager1_g_d6877ff2_42a8_4804_8802_6d49230dae8a_ctl00_txtPageNumber"))).send_keys(i)

Upvotes: 0

Views: 571

Answers (1)

Patrick
Patrick

Reputation: 81

after waiting for the element, since you need only the function onkeypress, try execute script.

driver.execute_script("if (WebForm_TextBoxKeyHandler(event) == false) return false;javascript:return isNumber(event);")

Upvotes: 1

Related Questions