I am trying to get in this website: "https://core.cro.ie/".
I can get in using normal web search, but I can't get in using selenium.
My code looks like this:
site= "https://core.cro.ie/"
driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))
driver.get(site)
driver.maximize_window()
Any ideas? Thank you very much
This code works fine for navigation ( I dont have Edge browser):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
site= "https://core.cro.ie/"
driver = webdriver.Firefox()
driver.get(site)
driver.maximize_window()
I have installed selenium prior running the test. It seems like the website has some sort of bot prevention mechanism but navigation works fine:
pip install selenium
Related
Currently using python and trying to have selenium click the "About" on google without using id. When I try to use .click() it does not execute, what is wrong with my code? I have looked at many videos and tutorials and it looks correct.
from selenium import webdriver
from time import sleep
browser = webdriver.Safari()
browser.get('http://google.com')
browser.maximize_window()
elm = browser.find_element_by_link_text('About')
browser.implicitly_wait(5)
elm.click()
I think, you can try using find_element_by_xpath.
First you will copy xpath of about link then you can try like below:
from selenium import webdriver
from time import sleep
browser = webdriver.Safari()
browser.get('http://google.com')
browser.maximize_window()
elm = browser.find_element_by_xpath('//*[#id="fsl"]/a[3]')
browser.implicitly_wait(5)
elm.click()
So the issue ended up being safari. For some reason the web driver safari was not allowing me to use .click. I switched to chrome and it worked.
I am using chromedriver.exe for Chrome version 80, and chrome version 80.0.3987.149. My selenium is up to date. I'm trying to send shortcuts to the browser in python and nothing is working. I've tried ActionChains, and elem.send_keys(). No shortcuts I've used have worked and I can't figure this out.
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import pyautogui
driver = webdriver.Chrome(executable_path=r'path/to/exe')
driver.get('https://www.google.com')
time.sleep(8)
elem = driver.find_element_by_xpath("//body")
elem.send_keys(Keys.CONTROL,'t') #Opens a new tab
This doesn't work! I've tried an ActionChain approach and that doesn't work either. Any help would be awesome.
I am trying to automate logging into my salesforce account. When I use my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser= webdriver.Firefox()
browser.get("https://xxxxx.my.salesforce.com/?
SAMLRequest=&startURL=%2Fidp%2Flogin%3Fapp%
3D0sp0g000000Gmhj&un=xxxxx.xxxxx%40xxxxx.com")
elem=browser.find_element_by_id("username")
elem.send_keys("xxxxx.xxxx#xxxxx.com")
elem_pass=browser.find_element_by_id("password")
elem_pass.send_keys("xxxxxxx")
rem_me=browser.find_element_by_id("rememberUn")
rem_me.click()
elem.send_keys(Keys.ENTER)
As you can see, I pass the link to the url, pass the usname, password and remember me.
When I run this with Selenium, it goes to a email 2FA authentication page.
But when I do it manually:
Copy the url mentioned above.
Paste it into the address bar of firefox browser.
The uname and pass show already populated.
When I hit enter, it logs me in. (No 2FA).
Is Salesforce somehow detecting that request is from selenium?
And is there a way to get around it?
Could this be related to this?
Different results when using Selenium + Python
Yup, I got it resolved. I had to import cookies from Firefox, and use them with Selenium. from selenium import webdriver from selenium.webdriver.common.keys import Keys import os os.chdir("C:\Users\tsingh\Desktop\Cookies") ffprofile = webdriver.FirefoxProfile('C:\Users\tsingh\Desktop\Cookies') browser = webdriver.Firefox(firefox_profile=ffprofile)
I’m working to make web crawler with python by using selenium
Here, I successfully got contents by using chromedriver, but problem occurred when I tried to make
Headless access crawling through PhantomJS. find_element_by_id, or find_element_by_name did not work
Is there any difference between these? Actually I am trying to make this as headless because I want to run this
Code in ubuntu server as a batch job without GUI support.
My script is like as below.
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import re
#driver = webdriver.PhantomJS('/Users/user/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs')
#driver = webdriver.Chrome('/Users/user/Downloads/chromedriver')
driver = webdriver.PhantomJS()
driver.set_window_size(1120, 550)
driver.get(url)
driver.implicitly_wait(3)
#here I tried two different find_tag things but both didn’t work
user = driver.find_element(by=By.NAME,value="user:email")
password = driver.find_element_by_id('user_password')
I am able to use some keys like Tab
browser.find_element_by_tag_name('body').send_keys(Keys.TAB)
But not Ctrl+f or Ctrl+p
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL +'f')
I also tried using xpath find_element_by_xpath & send_keys(Keys.CONTROL,'f') but still not working
You shall try by using action_chains in selenium webdriver
from selenium.webdriver.common.action_chains import ActionChains
#
# Your code
#
browser.find_element_by_tag_name('body')
ActionChains(browser).send_keys(Keys.CONTROL, "f").perform()
To be honest I have not known the answer before. I searched and run code using selenium.webdriver.common.action_chains but failed.
Then after more research, I was suggested to use pyautogui library. I don’t know how, but it worked for me… you can try the code.
# Import necessary libraries
from selenium import webdriver
import pyautogui
# to get the broswer
driver = webdriver.Chrome(executable_path="C:\Windows\chromedriver_win32 (1)\chromedriver.exe")
driver.maximize_window()
driver.get("https://www.google.com/")
# code to perform ctrl+F
pyautogui.hotkey('ctrl', 'f')