Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98221

How do i set browser width/height on initiation and how can i add tabs at the start? ChromeDriver Selenium Python

$
0
0

I have been struggling to adjust the browser width and height to be set during initialization. Currently i am using

...
driver = webdriver.Chrome(chrome_path)
options.add_argument("--width=300")
options.add_argument("--height=300")
driver.get(url)
...

This only opens the browser in its default size and then changes it to the size that i want after it is initiated. What i want is for it to open in the size given upon starting that task.

Secondly, is there a way for me to open up the browser window and then immediately add another tab? I tried using the Action Keys and also .send_keys but they both do not work as expected.

driver.get('www.google.com')
driver.find_element_by_css_selector('body').send_keys(Keys.CONTROL, 'T')
driver.get(page_address)

All this does is open google.com after about 10 seconds and then loads the page from page_address. I want it to not wait for that page to load full and to instantly open a new tab that will then load the page i tell it to from page_address.

I have also tried

driver.get('www.google.com')
driver.find_element_by_css_selector('body').send_keys(Keys.CONTROL + 'T')
driver.get(page_address)

If anyone has any idea please let me know. Thank you.

EDIT 1

using the ``execute_script``` allowed me to open a new tab almost instantly, although i feel like it would be faster if i can immediately change the size because that initiation seems to be slowing down the process. Here is the troubled code

            def startall():
                driver = []
                index = 0
                chrome_options = webdriver.ChromeOptions()
                for drive in range(0, num_tasks):
                    driver.append(webdriver.Chrome(chrome_path, chrome_options=chrome_options))
                for start_tasks in range(0, num_tasks):
                    chrome_options.add_argument('window-size=300,300')
                    options.add_experimental_option("detach", True)
                    drivers = driver[index]
                    index = index + 1
                    drivers.execute_script("window.open('{}')".format(page_address))

            start_all = Button(page2, text='Start All', bg='#1C2833', fg='#FDFEFE', font=("Helvetica", 14),
                               command=startall)
            start_all.place(x=900, y=5)

It is indented like this because of the amount of code and checks i am doing inside my code.


Viewing all articles
Browse latest Browse all 98221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>