Python Selenium Edge Webdriver doesn't open the Website - python

that's the first time I work with Selenium and I got the problem that I can't open a Website in Edge using Selenium.
from selenium import webdriver
driver = webdriver.Edge(executable_path="/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
url = "https://www.google.com/"
driver.get(url)
Please help me as fastest as possible. Thank you.

Related

Python Selenium - Clearing chrome cache

I'm trying to clear the cache from the chrome driver with selenium.
The below code worked fine for a day, and now it has stopped working for some reason. It redirects to the ClearBrowserData url, but it does not press enter to run the Clear Data button.
Am I doing something wrong? I would appreciate some help on this.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = 'path'
browser = webdriver.Chrome(executable_path = chromedriver)
browser.get('chrome://settings/clearBrowserData')
browser.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER)
beacuse shadowRoot
<settings-clear-browsing-data-dialog>
#shadow-root (open)
</settings-clear-browsing-data-dialog>

Selenium: Follow adfly redirect

Im trying to make a bot that visits my adfly link using the chrome webdriver. Every time I try to use the code below though, the webdriver tells me that there were too many redirects and doesn't follow through. The code below is just being used for testing at the moment:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"http://102.129.249.120:8080")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")
Image of error here
Okay so i figured it out. I can use tor with selenium to get access to adfly. Works great btw. Thanks for the help and time guys. If you want to see the code I used, here it is:
from selenium import webdriver
import os
os.popen(r'C:\Users\joldb\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"socks5://127.0.0.1:9050")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")

Passing requests session/cookies to Chrome webdriver

I am trying to send a few POST/GET requests then transfer the session/cookies to a Chrome webdriver with Selenium. As I am new to Selenium, I'm unsure of how to accomplish this. I have seen how people do Selenium session to requests, but that's not what I need. Any help would be appreciated as I have looked everywhere and can't see to find a solution.
import requests
from selenium import webdriver
driver = webdriver.Chrome()
s = requests.Session()
s.post('http://example.com')
s.get('http://example.com')
# need to trasnfer session/cookies to driver
driver.get('http://example.com')

Using Selenium in the background

I'm using Selenium and chrome webdriver but when I run scripts it opens a window. Is there any way that it can access the internet without the window popping up?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("https://ps.rsd.edu/public/")
elem = driver.find_element_by_name("account")
elem.send_keys("Username")
elem2 = driver.find_element_by_name("pw")
elem2.send_keys("Password")
elem.send_keys(Keys.RETURN)
driver.quit()
For example, this goes to my school's grade site and puts in a username and password but I want to do this without the browser popping up if that's possible.
I would suggest try using headless PhantomJs GhostDriver (which is a relatively new thing). As this is the native Selenium Webdriver way of doing it.
Download PhantomJs executables from http://phantomjs.org/download.html.
driver = webdriver.PhantomJS("./phantomjs") # path to phantomjs binary
driver.get("https://ps.rsd.edu/public/")
elem = driver.find_element_by_name("account")
elem.send_keys("Username")
elem2 = driver.find_element_by_name("pw")
elem2.send_keys("Password")
elem.send_keys(Keys.RETURN)
driver.quit()

Starting a browser in selenium

I want to run tests with selenium. IE gives me a modal error after bringing up IE 8 with this text "This is the initial start page for the WebDriver server" :
from selenium import webdriver
import time
browser = webdriver.Ie() # Get local session of IE
browser.get("http://www.google.com") # Load page
time.sleep(5)
browser.close()
So I tried Chrome.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.google.com")
time.sleep(5)
browser.close()
and Selenium errors for not having the right path to the chrome.exe application. Chrome is installed as expected... C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
A little help here would be greatly appreciated.
Have u downloaded the Chrome Driver?
To get set up, first download the appropriate prebuilt server. Make sure the server can be located on your PATH or specify its location via the webdriver.chrome.driver system property.
Then when u run
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.google.com")
time.sleep(5)
browser.close()
It should work.

Categories