1

I am trying to scrape some information from this website http://www.dubaitrade.ae/ja-terminal-1

I have to go to the terminal code column and select 'General Cargo'

Here is the HTML.

<select name="terminal" id="terminal1" style="width:52%" tabindex="3"> 
<option value="GC">General Cargo</option>
<option value="T1" selected="selected">Terminal One</option>
<option value="T2">Terminal Two</option>
<option value="T3">Terminal Three</option></select>

I am unsure if the difficulty is because it is nested within this tag.Meaning it is some kind of form.

<form name="vesselform" id="vesselLinkFormID" method="post" action="/pmisc/vessel.do;jsessionid=1da4f04d50b1a09ff55171820810948e8430f1ad26af4f30e765658bb25b3ffa.e34NaxuKaxmOaO0OaxmKc34Sa3j0">

I have tried

Select(driver.find_element_by_xpath('//*[@id="terminal1"]')).select_by_visible_text('General Cargo')
Select(driver.find_element_by_id('terminal1')).select_by_visible_text('General Cargo')
Select(driver.find_element_by_css_selector("terminal1"))
Select(driver.find_element_by_name('terminal1')).select_by_visible_text('General Cargo')      

I always get the error message unable to locate element.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jay Haran
  • 123
  • 1
  • 9

1 Answers1

0

Your code is near perfect but before you start looking out for the <select> tag you have to switch to the desired <iframe> with id as blockrandom inducing proper WebDriverWait as follows :

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver=webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("http://www.dubaitrade.ae/ja-terminal-1")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"blockrandom")))
Select(driver.find_element_by_xpath('//*[@id="terminal1"]')).select_by_visible_text('General Cargo')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you very much. Could you please explain why the following line of code is needed: "WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"blockrandom")))" – Jay Haran Apr 27 '18 at 15:55
  • @JayHaran Just like you I faced _NoSuchElementException_ and in those cases this [discussion](https://stackoverflow.com/questions/47993443/selenium-selenium-common-exceptions-nosuchelementexception-when-using-chrome/47995294#47995294) will help you. – undetected Selenium Apr 27 '18 at 15:59