I have just started taking a Python class and is my first experience with programming, other than a little HTML. I am trying to write a script for Instagram and would like to be able to get the Chrome browser into a mobile view. So my thought is to open the developer tools (CTRL+SHIFT+i) and then mobile (CTRL+SHIFT+m) How can I get Selenium to do this with Python code?
String selectAll = Keys.chord(Keys.ALT, Keys.SHIFT,"z");
driver.findElement(By.tagName("html")).sendKeys(selectAll);
I tried to modify this to get it to work but it didn't. Would I need to import something for the above block to work?
Here is the code i have and am trying to get to mobile mode after the existing code runs.
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
#mobile_emulation = { "deviceName": "iPhone 4" }
#chrome_options = webdriver.ChromeOptions()
#chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
#driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
#desired_capabilities = chrome_options.to_capabilities())
class InstaBot:
def __init__(self,username,pw,):
self.driver = webdriver.Chrome()
self.username = username
self.driver.get('https://instagram.com')
sleep(2)
self.driver.find_element_by_xpath("//a[contains(text(), 'Log in')]")\
.click()
sleep(2)
self.driver.find_element_by_xpath("//input[@name=\"username\"]")\
.send_keys(username)
self.driver.find_element_by_xpath("//input[@name=\"password\"]")\
.send_keys(pw)
self.driver.find_element_by_xpath('//button[@type="submit"]')\
.click()
sleep(4)
self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
.click()
sleep(4)
my_bot = InstaBot('username', 'password')
actions = ActionChains(driver)
actions.send_keys(Keys.CTRL, Keys.SHIFT, "i")
actions.perform()```