0

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)

1 Answer 1

1

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

2 Comments

What I usually do is whatever the function, I just put it on the execute script, eg. I just copied whatever is on the keypress. I have played it around some time and I have found out that it is also useful to have a javascript code as per below (clicking the radio button to be always true): driver.execute_script("document.getElementById('someID').checked = true;")
Got it. Thanks much.

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.