问题
I am playing around with the code below, and the weird thing is that it keeps opening a Chrome browser instead of a Firefox browser.
import requests
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from webbot import Browser
driver = webdriver.Firefox(executable_path= r'C:/path_here/geckodriver.exe')
web = Browser()
url = 'https://web_browser'
web.go_to(url)
# 1st validation
web.type('email_address' , into='username')
web.click('Continue')
# password
web.type('passwd' , into='password')
web.click('Next')
I got the geckodriver from the link below, and I change the extension from .gz to .exe, which I think is correct, but I'm not totally sure..
https://github.com/mozilla/geckodriver/releases
回答1:
This code will open Chrome browser windows, because:
"Web automation library for python which is based on the selenium framework"
If you look at the source you can see:
self.driver = webdriver.Chrome(executable_path=driverpath , chrome_options=options)
It means that you open two tabs in these two lines:
driver = webdriver.Firefox(executable_path= r'C:/path_here/geckodriver.exe')
web = Browser()
You don't actually need that. May be fixed in this way:
import requests
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from webbot import Browser
web = Browser()
url = 'https://web_site'
web.go_to(url)
# 1st validation
web.type('email' , into='username')
web.click('Continue')
# 2nd validation
web.type('email' , into='username')
web.click('Next')
# password
web.type('pass' , into='password')
web.click('Next')
# Now you are logged in!!
url = 'https://web_page'
web.go_to(url)
# upload CSV Source File:
WebElement = web.driver.find_element_by_class_name('ignore-inline-attach')
web.driver.sendKeys("C:/my_path/test.csv");
# Close browser.
web.close_current_tag()
It's not a Chrome issue. See my answer to your previous question!
Regards
回答2:
This ended up working for me.
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
wd = webdriver.Firefox(executable_path="C:/Utility/geckodriver.exe", firefox_profile=profile)
url = "https://www.google.com/"
wd.get(url)
# download geckodriver for windows 64-bit from here
# https://github.com/mozilla/geckodriver/releases
回答3:
You have to add these two references
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
After that you can make a test funtion like that using OpenQA.Selenium; using OpenQA.Selenium.Firefox;
public void test()
{
IWebDriver browser = new FirefoxDriver();//Open Page
browser.Navigate().GoToUrl("https://stackoverflow.com");//Close Page
browser.Close();
}
I hope that I could help you
来源:https://stackoverflow.com/questions/52229912/trying-to-get-firefox-working-with-selenium