1

I am unable to input text into the Booking Number textbox in: https://www.hmm21.com/cms/business/hongkong/export/vgmWithoutLogin/index.jsp

This is the html of the textbox using inspect on chrome:

<input style="width:200px;text-transform:uppercase;ime-mode:disabled;" type="text" maxlength="12" name="bookingNumber" value="">

This is the code I am using for now:

element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='bookingNumber']"))).send_keys('test')

I tried many other methods as well, like selecting using CSS Selector, absolute xpath, but I just cannot seem to be typing anything into the textbox.

I also tested the xpaths and CSS Selectors using ChroPath, a few other chrome extensions, xPath Finder on Firefox as well, and they all seemed to be working.

Would appreciate if anyone could help. Thanks.

Rong Heng
  • 25
  • 5
  • Can you try this without `ExpectedConditions` like this - `driver.find_element_by_xpath("//input[@name='bookingNumber']").send_keys('test')` – Kondasamy Jayaraman Mar 01 '19 at 03:19
  • Hi, I just tried that as well, same message, unable to locate element. I also tried click() first, before trying to send keys. I even added a 15 secs sleep to ensure the page is fully loaded. – Rong Heng Mar 01 '19 at 03:32

4 Answers4

0

Try clicking the element before sending keys, You can also excute a JavaScript to modify it's value.

.click()

Also If the input is displayed through JavaScript wait for the element to be present and not clickable.

.presence_of_element_located()
  • Thanks for the suggestion, but I tried sending keys on the next line instead of on the same line, and it could not even reach the send keys line because an exception was thrown for being unable to find the textbox. I also just tried clicking first, same exception. – Rong Heng Mar 01 '19 at 03:28
  • The input is loaded through AJAX, Wait for the element to be present not clickable. – Z.Developer Mar 01 '19 at 03:42
  • Yea I tried that previously as well, didn't work out. I just tried it again to be sure, and also with the click first, didn't work either. – Rong Heng Mar 01 '19 at 04:10
0

You should switch the iframe first, use

WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it(self.driver.find_element_by_id('_frame1')))

Because the Booking Number textbox input element is in a new iframe named '_frame1'.

Hope it will help you.

林少峰
  • 93
  • 1
  • 1
  • 6
0

To send a character sequence to the element associated with the text Booking Number as the desired elements are within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following solution:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#_frame1[src='/ebiz/ebooking/vgm/indexWithoutlogin.jsp']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='bookingNumber']"))).send_keys('Rong Heng')
      
    • Using XPATH:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='_frame1' and @src='/ebiz/ebooking/vgm/indexWithoutlogin.jsp']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='bookingNumber']"))).send_keys('Rong Heng')
      

Here you can find a relevant discussion on Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

This element is inside iframe as ChroPath suggested. So first you will have to switch to iframe and perform the action. Sometime if sendKeys doesn't work on input box then try clear/click() method before sending keys in box.

enter image description here