6

I am trying to change the input field value in a form input, but unable to do so.

Input value is at this URL

Email: [email protected] PW: Testing@123

On the page form appears after these actions:

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 When I try to change it using selenium or even if JS, it doesn't seem to change when we submit the form by pressing "Send Order"

My code trails are:

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 have also tried

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

But still when I submit it doesn't seem to change.

2
  • Website require login. can you share if its for testing purpose or share the HTML of element Commented Jun 11, 2020 at 10:15
  • @NarendraR editing the question to add credentials Commented Jun 11, 2020 at 10:24

2 Answers 2

4

To perform the following steps:

  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"
  4. Send the value 10000 to the <input> field.

You have to induce WebDriverWait for the element_to_be_clickable() and you can use 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("[email protected]")
    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 of constructing the answer:

Entry Price you set must be higher or equal to 9786.7

  • Browser Snapshot:

primaxbt

Sign up to request clarification or add additional context in comments.

4 Comments

can you explain what WebDriverWait(driver, 10).until(EC.element_to_be_clickable does. In 10 to 12 trails, it failed 8-9 times, before it, i used time.sleep which showed better results
@curious_nustian See the discussion How to get rid of the hardcoded sleep()? to understand why not to use time.sleep() and WebDriverWait not working as expected discussion for element_to_be_clickable
what can be cause of raise TimeoutException(message, screen, stacktrace) despite the element is visible
WebDriverWait ignores NoSuchElementException and on timeout raises TimeoutException
2

While inspecting the require element i found that there is an iframe on which the content wrapped.

enter image description here

So to deal with frames in selenium first you need to switch into right iframe and then it allows you to interact with the elements.

  1. Switch using iframe indexes

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

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

    driver.switch_to.frame('frame name') #make sure name attribute available in frame tag
    

This is how you can use 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")))

And use this locator to enter text in texxtbox

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.