Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting attribute value selenium python

enter image description here

In this example, this is a database table that changes dynamically depending on how many records you select to display. I am creating a script that runs through each row to grab data, however, if you go into a specific record, or refresh the page the view resets each time to page 1. So for example, if you were on page 5 and hit refresh, the page will refresh the view to page 1.

My work around is to pass in the value of 500 and then select the option where the value will be 500. This will increase the results to show all on one page so that I don't have to refresh the page.

I am trying to access option value 50 to change it to the value of 500. Then I will use the .click() method to change the view to this value.

I have tried to use this way with no luck.

driver.execute_script("document.getElementById('dt_a_length').getElementsByTagName('option').setAttribute('value', '500')")

I would greatly appreciate some help with this. Thank you!

like image 934
dataviews Avatar asked Mar 06 '26 06:03

dataviews


1 Answers

you may also do this to set 'value' for the 'element' :

driver.execute_script("arguments[0].setAttribute('value',arguments[1])",element, value)
like image 55
Suraj Shrestha Avatar answered Mar 08 '26 19:03

Suraj Shrestha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!