<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akram Siddiqui</title>
    <description>The latest articles on DEV Community by Akram Siddiqui (@siddiquiakram84).</description>
    <link>https://dev.to/siddiquiakram84</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1250060%2F82277edf-df9b-408a-a01d-9fc2f979ccfa.png</url>
      <title>DEV Community: Akram Siddiqui</title>
      <link>https://dev.to/siddiquiakram84</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/siddiquiakram84"/>
    <language>en</language>
    <item>
      <title>How to handle Permission Pop-ups using Selenium WebDriver | Selenium |Python|</title>
      <dc:creator>Akram Siddiqui</dc:creator>
      <pubDate>Sat, 06 Jan 2024 06:21:50 +0000</pubDate>
      <link>https://dev.to/siddiquiakram84/how-to-handle-permission-pop-ups-using-selenium-webdriver-selenium-python-3gcl</link>
      <guid>https://dev.to/siddiquiakram84/how-to-handle-permission-pop-ups-using-selenium-webdriver-selenium-python-3gcl</guid>
      <description>&lt;p&gt;Hello Dev Community,&lt;/p&gt;

&lt;p&gt;I'm currently working on Selenium WebDriver automation with Python, focusing on handling permission pop-ups in headless mode on a Linux machine. Specifically, I want to handle the location permission alert and allow it to make my tests run smoothly.&lt;/p&gt;

&lt;p&gt;In non-headless mode, the following code works perfectly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options as ChromeOptions
from time import sleep

# Chrome options setup
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--incognito')

# Configure content settings to disable notifications and geolocation
content_settings = {'notifications': 0, 'geolocation': 0}
profile = {'managed_default_content_settings': content_settings}
prefs = {'profile': profile}
chrome_options.add_experimental_option('prefs', prefs)

# Add arguments to disable notifications, geolocation, and media stream
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--disable-geolocation')
chrome_options.add_argument('--use-fake-ui-for-media-stream')

path = r"C:\Program Files (x86)\chromedriver-win64\chromedriver.exe"

# WebDriver setup using WebDriver Manager
service = ChromeService(path)
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.maximize_window()

# Navigate to the specified URLs
driver.get('https://www.cleartrip.com/')
driver.get('https://whatmylocation.com/')

sleep(15)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when I switch to headless mode on a Linux machine, the location permission alert is not being handled as expected. Here's the headless mode code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_headless_chrome_driver():
    chrome_options = ChromeOptions()
    chrome_options.add_argument('--start-maximized')
    chrome_options.add_argument('--headless')

    # Allow geolocation
    chrome_options.binary_location = CHROME_BINARY_PATH
    chrome_options.add_argument('window-size=1920x1080')
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")

    # Handling geolocation
    chrome_options.add_argument('--incognito')

    # Configure content settings to disable notifications and geolocation
    content_settings = {'notifications': 1, 'geolocation': 1}
    profile = {'managed_default_content_settings': content_settings}
    prefs = {'profile': profile}
    chrome_options.add_experimental_option('prefs', prefs)

    # Add arguments to disable notifications, geolocation, and media stream
    chrome_options.add_argument('--disable-notifications')
    chrome_options.add_argument('--disable-geolocation')
    chrome_options.add_argument('--use-fake-ui-for-media-stream')

    service = ChromeService(executable_path=CHROMEDRIVER_PATH)
    driver = webdriver.Chrome(service=service, options=chrome_options)

    return driver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**&lt;/p&gt;

</description>
      <category>python</category>
      <category>selenium</category>
      <category>linux</category>
      <category>headless</category>
    </item>
    <item>
      <title>How to handle Permission Pop-ups using Selenium WebDriver | Selenium |Python|</title>
      <dc:creator>Akram Siddiqui</dc:creator>
      <pubDate>Sat, 06 Jan 2024 06:21:45 +0000</pubDate>
      <link>https://dev.to/siddiquiakram84/how-to-handle-permission-pop-ups-using-selenium-webdriver-selenium-python-f3o</link>
      <guid>https://dev.to/siddiquiakram84/how-to-handle-permission-pop-ups-using-selenium-webdriver-selenium-python-f3o</guid>
      <description>&lt;p&gt;Hello Dev Community,&lt;/p&gt;

&lt;p&gt;I'm currently working on Selenium WebDriver automation with Python, focusing on handling permission pop-ups in headless mode on a Linux machine. Specifically, I want to handle the location permission alert and allow it to make my tests run smoothly.&lt;/p&gt;

&lt;p&gt;In non-headless mode, the following code works perfectly:&lt;/p&gt;

&lt;p&gt;**from selenium import webdriver&lt;br&gt;
from webdriver_manager.chrome import ChromeDriverManager&lt;br&gt;
from selenium.webdriver.chrome.service import Service as ChromeService&lt;br&gt;
from selenium.webdriver.chrome.options import Options as ChromeOptions&lt;br&gt;
from time import sleep&lt;/p&gt;

&lt;h1&gt;
  
  
  Chrome options setup
&lt;/h1&gt;

&lt;p&gt;chrome_options = webdriver.ChromeOptions()&lt;br&gt;
chrome_options.add_argument('--incognito')&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure content settings to disable notifications and geolocation
&lt;/h1&gt;

&lt;p&gt;content_settings = {'notifications': 0, 'geolocation': 0}&lt;br&gt;
profile = {'managed_default_content_settings': content_settings}&lt;br&gt;
prefs = {'profile': profile}&lt;br&gt;
chrome_options.add_experimental_option('prefs', prefs)&lt;/p&gt;

&lt;h1&gt;
  
  
  Add arguments to disable notifications, geolocation, and media stream
&lt;/h1&gt;

&lt;p&gt;chrome_options.add_argument('--disable-notifications')&lt;br&gt;
chrome_options.add_argument('--disable-geolocation')&lt;br&gt;
chrome_options.add_argument('--use-fake-ui-for-media-stream')&lt;/p&gt;

&lt;p&gt;path = r"C:\Program Files (x86)\chromedriver-win64\chromedriver.exe"&lt;/p&gt;

&lt;h1&gt;
  
  
  WebDriver setup using WebDriver Manager
&lt;/h1&gt;

&lt;p&gt;service = ChromeService(path)&lt;br&gt;
driver = webdriver.Chrome(service=service, options=chrome_options)&lt;br&gt;
driver.maximize_window()&lt;/p&gt;

&lt;h1&gt;
  
  
  Navigate to the specified URLs
&lt;/h1&gt;

&lt;p&gt;driver.get('&lt;a href="https://www.cleartrip.com/'"&gt;https://www.cleartrip.com/'&lt;/a&gt;)&lt;br&gt;
driver.get('&lt;a href="https://whatmylocation.com/'"&gt;https://whatmylocation.com/'&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;sleep(15)**&lt;/p&gt;

&lt;p&gt;However, when I switch to headless mode on a Linux machine, the location permission alert is not being handled as expected. Here's the headless mode code:&lt;/p&gt;

&lt;p&gt;**def create_headless_chrome_driver():&lt;br&gt;
    chrome_options = ChromeOptions()&lt;br&gt;
    chrome_options.add_argument('--start-maximized')&lt;br&gt;
    chrome_options.add_argument('--headless')&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Allow geolocation
chrome_options.binary_location = CHROME_BINARY_PATH
chrome_options.add_argument('window-size=1920x1080')
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

# Handling geolocation
chrome_options.add_argument('--incognito')

# Configure content settings to disable notifications and geolocation
content_settings = {'notifications': 1, 'geolocation': 1}
profile = {'managed_default_content_settings': content_settings}
prefs = {'profile': profile}
chrome_options.add_experimental_option('prefs', prefs)

# Add arguments to disable notifications, geolocation, and media stream
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--disable-geolocation')
chrome_options.add_argument('--use-fake-ui-for-media-stream')

service = ChromeService(executable_path=CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service, options=chrome_options)

return driver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;**&lt;/p&gt;

</description>
      <category>python</category>
      <category>selenium</category>
      <category>linux</category>
      <category>headless</category>
    </item>
  </channel>
</rss>
