Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete_all_cookies and multiple workers #1783

Closed
hwkongsgaard opened this issue Mar 11, 2016 · 3 comments
Closed

delete_all_cookies and multiple workers #1783

hwkongsgaard opened this issue Mar 11, 2016 · 3 comments

Comments

@hwkongsgaard
Copy link

Expected Behavior -

Hi, when I run selenium with phantomjs, python celery using multiple workers. There seems to be conflict between the different sessions, or that sessions interfere with each other.

Does driver.delete_all_cookies() delete cookie for all sessions?

Simple code example

class browser(Task):
    def __init__(self):
        dcap = dict(DesiredCapabilities.PHANTOMJS)
        dcap["phantomjs.page.settings.userAgent"] = (
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
            "(KHTML, like Gecko) Chrome/15.0.87"
        )
        self.driver = webdriver.PhantomJS(desired_capabilities=dcap)
        self.driver.set_window_size(1024, 768) # optional

    def get_data(self,x):
        x = json.loads(x)

        if True:
            self.driver.delete_all_cookies()
            self.driver.get('http://www.mysite.com')
            sbtn = self.driver.find_element_by_id( "ctl00_ctl00_MainWrap_MainContent_FullRegion_ContentLeftRegion_ContentLeftMenuRegion_RekoFilter_ctl00_tbVIN")
            sbtn.send_keys(x['key'])
            self.driver.find_element_by_id( "ctl00_ctl00_MainWrap_MainContent_FullRegion_ContentLeftRegion_ContentLeftMenuRegion_RekoFilter_ctl00_btnSearch").click()
            car_info = self.driver.find_element_by_class_name("carInfo")


@app.task(name='hent_bilnummer_biltema', base=browser)
def get_something(_):
    get_something.get_data(_)

Actual Behavior -

Browser cannot find element, wrong page.

Steps to reproduce -

It works with just one worker not multiple

@hwkongsgaard hwkongsgaard changed the title delete_all_cookies deletes and multiple workers delete_all_cookies and multiple workers Mar 11, 2016
@lukeis
Copy link
Member

lukeis commented Mar 11, 2016

would appear that phantomjs stores all cookies in a default cookie file -
http://phantomjs.org/api/command-line.html --cookies-file

as a workaround you can make sure that each session gets its own cookie file:

import tempfile
webdriver.PhantomJS(desired_capabilities=caps, service_args=["--cookies-file="+tempfile.mkstemp()[1]])

@lukeis lukeis closed this as completed in de23cf5 Mar 11, 2016
@hwkongsgaard
Copy link
Author

Thanks

@lukeis
Copy link
Member

lukeis commented Mar 11, 2016

it's in the phantomjs docs where i found it ;)

@lock lock bot locked and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants