4

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:
9
  • cant you just run some javascript to directly set the value ? so document.getElementById("selectionid").value = 1000 Commented Nov 8, 2019 at 16:55
  • What headless browser driver are you using? PhantomJS? Commented Nov 8, 2019 at 16:57
  • @JohnGordon - I am using Chromedriver version 78. running Selenium, written in python. Commented Nov 8, 2019 at 17:00
  • @WilliamBright - not sure how but I will see if i can find a way to try it. Commented Nov 8, 2019 at 17:01
  • If you're using Chrome, how is that headless? I feel like I'm missing something. Commented Nov 8, 2019 at 17:02

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

1 Comment

This solved my problem. Thank you for the input, I didnt realize that running it headless would alter window size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.