0
votes

I need help. After I've disabled Javascript on PhantomJS web driver I can't get or click any element using browser.find_element_by_id or any similar method.

Here is how I set Phantom:

def phantom_settings_function():
    # PhantomJS settings
    phantom_settings = dict(DesiredCapabilities.PHANTOMJS)
    phantom_settings['phantomjs.page.settings.userAgent'] = ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36')
    phantom_settings['phantomjs.page.settings.javascriptEnabled'] = False,   
    phantom_settings['phantomjs.page.settings.loadImages'] = False,
    phantom_settings['phantomjs.page.browserName'] = 'Google Chrome'

    return phantom_settings
browser = webdriver.PhantomJS(desired_capabilities=phantom_settings_function(), service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])

This is the how I how I try to click on element:

browser.find_element_by_id('c_btnPriceRange').click()

And I get this error:

selenium.common.exceptions.NoSuchElementException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"96","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:52780","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"POST","post":"{\"value\": \"c_btnPriceRange\", \"using\": \"id\", \"sessionId\": \"871daac0-147f-11e7-bfdf-4dce0d86731e\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/871daac0-147f-11e7-bfdf-4dce0d86731e/element"}} Screenshot: available via screen

I've tried explicit wait for the element and it doesn't work, when I print the content of the web page I get complete HTML code with element in it. Is disabling JavaScript making Selenium unable to run command or something?

I really need help with this.

Thank you

1
selenium uses javascript to interact with elements.. you need it enabledCorey Goldberg
I guessed that that could be a problem but it worked when I disabled it on Chrome and Firefox. Thank youSteve S

1 Answers

0
votes

I also had an NoSuchElementException issue with the PhantomJS web driver. My fix, which was based on

Python/Selenium/PhantomJS - Data retained between execution

was to add

browser.implicitly_wait(10)
browser.set_window_size(1120, 550)

before

browser.find_element_by_id