Alter the input field value in Selenium with Python

I'm having trouble updating the input field value in a form, even after attempting various methods.

The input value can be found at this URL

Email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="df89bab3bef1bebbb2b69fb8b2beb6b3f1bcb0b2">[email protected]</a>
PW: Testing@123

After performing certain actions on the page, a form appears. Here are the steps:

1. Click on the "Sell Order" red button on the left side of the Dashboard widget
2. A popup will appear, choose "Order Type" as "Limit"
3. Another form field named "Limit Price" will appear

https://i.sstatic.net/OvBFi.png I've tried changing it using Selenium and JavaScript, but the value remains unchanged when submitting the form by clicking "Send Order".

This is the code I've used:

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')

I've also attempted this approach:

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

Despite these efforts, the input value remains unchanged upon submission.

Answer №1

Follow these steps:

  1. Click on the "Sell Order" red button on the left side of the Dashboard widget
  2. When a popup appears, choose "Order Type" as "Limit"
  3. A new field called "Limit Price" will be shown
  4. Enter the value 10000 into the <input> field.

You need to utilize WebDriverWait for the element_to_be_clickable() and you can apply the following Locator Strategies:

  • Code Block:

    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("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4016252c216e21242d2900272d21292c6e232f2d">[email protected]</a>")
    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()
    
  • Note: At the time this answer was created:

The Entry Price should be equal to or greater than 9786.7

  • Browser Snapshot:

https://i.sstatic.net/Lm253.png

Answer №2

Upon examining the require element, I noticed that it contained an iframe housing the content.

https://i.sstatic.net/6VtFN.png

When dealing with frames in selenium, the first step is to switch to the correct iframe in order to interact with the elements within.

  1. Switch by using iframe indexes

    driver.switch_to.frame(0)
    
  2. Switch by using the iframe element

    main_frame = driver.find_element_by_css_selector('iframe.ng-star-inserted')
    driver.switch_to.frame(main_frame)
    
  3. Switch by using the iframe name

    driver.switch_to.frame('frame name') #ensure the name attribute is available in the frame tag
    

You can also employ an Explicit wait condition to switch into it

WebDriverWait(driver, 45).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe.ng-star-inserted")))

Finally, use this locator to enter text in a textbox

driver.find_element_by_xpath("//span[contains(.,'Limit Price')]/following-sibling::span//input").send_keys('6700')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

To utilize a spread argument, it is essential for it to either be in tuple form or be supplied to a rest

I am currently learning TypeScript and working on converting my project to TypeScript. However, I encountered an error while trying to use spread arguments. I have researched this topic, but I am still unsure of the correct usage. Here is my current appro ...

Tips for creating a continuous scroll up and down animation within an overflow container using React

Currently, I am dealing with an overflow list of items that has a fixed height to ensure it can always be scrolled. The desired effect is for the overflow div to scroll down its content over a span of 4 seconds with a 0.5-second delay, and then scroll up ...

When trying to make a jQuery call using ajax, there is no response being received

I'm facing a slight issue with a gift list that is generated from SQL. My objective is to display each row as a form with a textbox and a button. When the button is clicked, I want to send the textbox value and an ID number (hidden field value) to a f ...

Using jQuery, it is possible to automatically generate a new HTML input element and access it within

My issue is: I am facing a problem with a dynamically generated table on my page using ajax-jquery My table consists of 3 <td> elements: 1 for name and 2-3 for checkboxes representing parameters I have set up an event for all input checkboxes to d ...

How to selectively display specific columns when outputting JSON to a dynamic HTML table?

I'm looking to output specific JSON data in an HTML table with JavaScript. The headers will remain the same, but the JSON content will vary. Currently, I have a working function that generates the entire table using JavaScript: <body> ...

printing jquery value inside html elements

I have a jQuery code snippet that is currently displaying an alert popup when triggered. However, I would like to print the result in the HTML body instead. I attempted the following but it did not work: // Do What You Want With Result .......... :) $(" ...

Create a Jest unit test for a specific function

I started my first unit test in react with jest this afternoon. The initial 5 tests I need to do involve testing the return functions, which isn't too difficult. However, I'm struggling to understand how to perform unit testing on my login funct ...

Transferring information between an ASP web form page and an Angular2 application

Currently, I am working on a project that involves dealing with a legacy WebForms system. The system is gradually being updated to Angular 2, but the transition is happening incrementally. In order to effectively integrate information from the legacy sect ...

Is there a specific regex pattern available to identify CSS and JavaScript links within an HTML file?

Currently, I am using a straightforward gulp task to compress my CSS and JS files. The task appends a .min extension to the names of the compacted files. Now, I want to make changes in the HTML to direct to these new compressed files, like so: Replace thi ...

How can you calculate the ratio of one property value to another in AngularJS?

In my code, I am using ng-repeat to display data values from an object. <div ng-controller="myctrl"> <ul ng-repeat="number in numbers"> <li><span ng-bind="number.first"></span></li> <li><span ng-bind ...

The menu element is present but Selenium fails to click on it

My current task involves automating a scenario where I need to hover over one element and then click on another element from the submenu. This process is being implemented using CSS selectors for testing IE webdriver. Our software offers navigation in 4 d ...

The Allure report generator is failing to generate a report for cucumber version 7

Recently, I updated the cucumber version to 7.2.3, but unfortunately, Allure stopped generating reports (showing unknown report and NaN%). Surprisingly, it still looks for the config file in the same directory. However, I doubt it's an issue with the ...

Whenever I implement JavaScript validation on my HTML page, it causes the page to become un

Whenever I try to enter more than 30 to 40 characters in the password input field on my HTML page, all web browsers become unresponsive. This issue persists even if I modify the minimum length and other requirements to 50. I am new to JavaScript. <!D ...

Running a Robot Framework test case to initialize a Chrome browser without automatically opening a URL

Is there a way to open a chrome browser in Robot framework without launching any URL? For example, using the command: 'Open Browser | http://google.com | chrome' opens a new chrome browser window with google page loaded. However, I am looking ...

Adjust the color of radio button text with Jquery

Here is a sample of radio buttons: <input type='radio' name='ans' value='0'> Apple <input type='radio' name='ans' value='1'> Banana <input type='radio' name='ans&apo ...

Callback function not being triggered in Jquery's getJson method

I am currently faced with a javascript conundrum. Below is the snippet of code that I have been working on: $.get("categories/json_get_cities/" + stateId, function(result) { //code here }, 'json' ); ...

Is it possible to have two unique keys in a single MongoDB schema?

Currently attempting to achieve this functionality using mongoose: const newContent = new Schema({ heading: { type: String, unique: true }, url: { type: String, unique: true }, //... }); However, an error is being thrown: MongoError: E11000 dupl ...

Organize information in a React table following a predetermined sequence, not based on alphabetical order

As a beginner with React, I'm looking to sort my data by the column "Status" in a specific order (B, A, C) and vice versa, not alphabetically. The data structure looks like this: export interface Delivery { id: number; name: string; amount: num ...

The Grid within the Container is presented vertically rather than horizontally

I followed the coding style exactly as shown in a recent tutorial on YouTube, where the cards were displayed in a row. However, when I implemented it, they are appearing strangely in a column. Why is this happening? The default should be inline. Even afte ...

Can the AngularJS icon adapt to different lists?

I'm currently developing in AngularJS / Jade and I need to implement functionality where an icon changes when a user clicks on something. The code I have right now looks like this: a(onclick='return false', href='#general', data-t ...