'Selenium: Can't access an input element using Selenium
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"> </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>
Solution 1:[1]
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;

So Selenium won't be able to interact with the element unless it's visible, enabled and interactable(clickable).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | undetected Selenium |
