0

Code trials:

import selenium
from selenium import webdriver

PATH = 'C:\Program Files (x86)\chromedriver.exe'

driver = webdriver.Chrome(PATH)
driver.get("https://oncf-voyages.ma")

origin = driver.find_elements_by_xpath('/html/body/div[1]/section/div[1]/div[2]/main/div[1]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div/div/div[2]/div/input')

origin.send_keys("something")
origin.send_keys(Keys.RETURN)

I used the python code above to try and practice some basic operations with selenium but I can't access an input clause Here's the website that I'm working on : https://www.oncf-voyages.ma/ This is a part of the html code of the website:

<div class="ant-col SearchForm_col ant-col-xs-24 ant-col-md-24 ant-col-xl-24 ant-col-xxl-24" style="padding-left: 15px; padding-right: 15px;"><label class="SearchForm_label">Ma gare de départ</label><div class="InputWrapper"><div id="origin" class="SelectPicker SelectWidget ant-select ant-select-enabled"><div class="ant-select-selection
    ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="b5b887d5-0fcf-488c-dc1a-9dca53b48787" aria-expanded="false" tabindex="0"><div class="ant-select-selection__rendered"><div unselectable="on" class="ant-select-selection__placeholder" style="display: block; user-select: none;">Ma gare de départ</div><div class="ant-select-search ant-select-search--inline" style="display: none;"><div class="ant-select-search__field__wrap"><input id="origin" autocomplete="off" class="ant-select-search__field" value=""><span class="ant-select-search__field__mirror">&nbsp;</span></div></div></div><span class="ant-select-arrow" unselectable="on" style="user-select: none;"><i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></div></div></div></div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
EVOLVE
  • 1
  • 2
  • it's a little odd that the input has no "type" attribute.... but try with XPATH of //input[@id='origin'] – pcalkins Apr 06 '22 at 19:34

1 Answers1

0

The <input> with you are trying to locate with the xpath:

/html/body/div[1]/section/div[1]/div[2]/main/div[1]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div/div/div[2]/div/input

is within it's ancestor <div> with style attribute set as display: none;

oncf-voyages-ma

So Selenium won't be able to interact with the element unless it's visible, enabled and interactable(clickable).

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • hey thanks for your feedback, i'm still a beginner with selenium so can you give me a solution for that problem ? or is it even possible to do that or not ? – EVOLVE Apr 06 '22 at 23:42
  • @EVOLVE Ofcoarse that's possible but you have to raise a new question as per your new requirement. – undetected Selenium Apr 06 '22 at 23:54