How can I change an attribute value in the DOM using Selenium and Python

后端 未结 2 658
名媛妹妹
名媛妹妹 2021-01-20 10:05

I\'m trying to navigate through a website using Python and Selenium and I\'ve run into an issue that I can\'t figure out how to solve (assuming it\'s even possible!)

相关标签:
2条回答
  • 2021-01-20 10:47
    dimension = image.size['width'] * image.size['height']
    driver.execute_script('arguments[0].setAttribute("dimension","{}");'.format(dimension), image)
    
    0 讨论(0)
  • 2021-01-20 11:04

    You can try this but understand that the site may not be OK with you sending whatever for a value. It may still limit the value to 100, etc.

    The Javascript part just takes the element you passed it and sets the value to whatever you pass in, e.g. "300".

    select = driver.find_element_by_id("uniqueid")
    WebDriver.execute_script("arguments[0].value = arguments[1]", select, "300")
    
    0 讨论(0)
提交回复
热议问题