I am attempting to select an option from a drop down menu that expands the records on a page. It works fine when I am not running headless. When I run in headless I get a timeout exception error while the page waits to find the element.
<select name="ctl00$ContentPlaceHolder1$uxTabContracts$uxTabPanelWaintingApproval$uxGridList$ctl05$uxUCGridViewPagingTemplate$uxDropDownListPageSize" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$uxTabContracts$uxTabPanelWaintingApproval$uxGridList$ctl05$uxUCGridViewPagingTemplate$uxDropDownListPageSize\',\'\')', 0)" id="ContentPlaceHolder1_uxTabContracts_uxTabPanelWaintingApproval_uxGridList_uxUCGridViewPagingTemplate_uxDropDownListPageSize">
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option selected="selected" value="1000">1000</option>
</select>
I have tried using the XPATH, the ID, and Name.
wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="ContentPlaceHolder1_uxTabContracts_uxTabPanelWaintingApproval_uxGridList_uxUCGridViewPagingTemplate_uxDropDownListPageSize"]'))) # wait for option to expand page
ExpandRecords = Select(chrome.find_element_by_xpath('//*[@id="ContentPlaceHolder1_uxTabContracts_uxTabPanelWaintingApproval_uxGridList_uxUCGridViewPagingTemplate_uxDropDownListPageSize"]')) # define element to expand page
ExpandRecords.select_by_value('1000') # select page size option from dropdown
The expected result is to select '1000' records and that the page will expand and move on to the next piece of code which will select the necessary records I need. What happens is nothing. and I get a timeout exception.
line 289, in Import_To_CRM
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="ContentPlaceHolder1_uxTabContracts_uxTabPanelWaintingApproval_uxGridList_uxUCGridViewPagingTemplate_uxDropDownListPageSize"]'))) # wait for option to expand page
selenium.common.exceptions.TimeoutException: Message:
For headless
browser you have to set the window size to fire on event.Because headless browser can't recognize where to click without window size.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('window-size=1920x1080');
If above option doesn't work then check if the website is blocking in headless mode using
print(driver.page_source)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With