How to find and write inside an input tag with selenium python

后端 未结 1 1763
旧巷少年郎
旧巷少年郎 2021-01-26 05:51

I would like to change a value of a input tag that haves the value 20 to 110 in the website https://www.tradingview.com/chart/. How can I actually do that?(all of that using sel

相关标签:
1条回答
  • 2021-01-26 06:24
    1. Locate the element you would like to interact with using your favourite browser developer tools

    2. Choose an appropriate Locator Strategy which will allow to uniquely match the element at the page
    3. Locate the element
    4. Wrap the locating code into an Explicit Wait this way your test will be more robust and reliable
    5. Use WebElement APIs to interact with elements

    Example code:

    driver.get("https://www.tradingview.com/chart/")
    
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@class,'format')]"))).click()
    input = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//input[contains(@class,'innerInput')]")))
    driver.execute_script("arguments[0].value=30", input)
    
    0 讨论(0)
提交回复
热议问题