gpt4 book ai didi

javascript - 如何使用 Selenium 和 Python 更改输入字段值

转载 作者:行者123 更新时间:2023-12-03 16:21:03 26 4
gpt4 key购买 nike

我正在尝试更改表单输入中的输入字段值,但无法这样做。

输入值在此URL
Email: Vela.admi@gmail.comPW: Testing@123
在这些操作之后出现在页面上的表单:

1. on left side click on "Sell Order" red button in Dashboard widget
2. a popup will appear on click, select "Order Type" as "Limit"
3. a new formfield appears, named "Limit Price"


Required Field
当我尝试使用 selenium 甚至 JS 更改它时,当我们通过按“发送订单”提交表单时它似乎没有改变

我的代码轨迹是:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time

driver.get(url)
driver.find_element_by_css_selector('#gwt-uid-770 > span > span > input').send_keys('6700')


我也试过
driver.execute_script("document.querySelector('#gwt-uid-770 > span > span > input').value=6700")

但是当我提交时,它似乎并没有改变。

最佳答案

要执行以下步骤:

  • 在左侧单击仪表板小部件中的“卖出订单”红色按钮
  • 点击会弹出一个窗口,选择“订单类型”为“限价”
  • 出现一个新的表单域,名为“Limit Price”
  • 发送值 10000<input> field 。

  • 你要诱导 WebDriverWait对于 element_to_be_clickable()您可以使用以下 Locator Strategies :
  • 代码块:
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.keys import Keys

    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get('https://primexbt.com/id/sign-in?redirect=%2Fmy%2Ftrade')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[formcontrolname='email']"))).send_keys("Vela.admi@gmail.com")
    driver.find_element_by_css_selector("input[formcontrolname='password']").send_keys("Testing@123")
    driver.find_element_by_css_selector("span.mat-button-wrapper").click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.popup-close"))).click()
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.ng-star-inserted")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.price.price-bid"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='selectBox--label' and text()='Market']"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='dropDown--list']//li[contains(., 'Limit')]"))).click()
    element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//label[text()='Limit Price']//following::span[1]//span[@class='numericStepper--input']//input[@class='gwt-TextBox']")))
    ActionChains(driver).click(element).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).send_keys("10000").perform()
  • 备注 :在构建答案时:

  • Entry Price you set must be higher or equal to 9786.7


  • 浏览器快照:

  • primaxbt

    关于javascript - 如何使用 Selenium 和 Python 更改输入字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62320910/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com