Basic runtime script error on python with selenium - python

I would like to point out that I am a beginner and that I started barely 48 hours ago.
I want to code a script that runs a page, enters username and password, click in the login button and clicks in a tab once logged in.
But I encounter an error, it only opens the page for me and does not enter any id/pw and click.
I tried to search and try some changes in the path but it doesn't change anything, and at worst doesn't launch my page anymore, I'm a little lost so I ask for your help please.
enter image description here

From the Selenium docs Finding Web Elements
So in your code,
import By from selenium.webdriver.common.by import By
and use wb.find_element(By.XPATH,"your_xpath")

Related

Attempting to get user input for opening URL? Python Selenium

This is my third day ever using Python, and I would like to know if there is a way to get user input for opening a URL. Meaning I would like to know how to ask the user what URL they would like to open and run the code provided in my py file. I tried something simplistic like
from selenium import webdriver
driver = webdriver.Chrome()
print('Link?')
webPage = input()
driver.get(webPage)
but it just opens a tab first in PyCharm without asking anything, then fails to open the link the user may have put in. Again I would like to apologize if the code is horrendous, pretty new at this lol. Appreciate any help, thanks!

How to compare the screen to a screenshot in Python

I'm making a Python program that opens Target and buys an item entered by the user. If the item is unavailable, the program does nothing and prints a message in the console. To check if the item is available, I need to check if the screen includes something similar to a screenshot I took. The screenshot is shown below.
Can anyone help me with this?
Well, you sure can compare two screenshots, using library as matplotlib, PIL or opencv (or even numpy) but I guess the easiest path is to use selenium (if you automate your navigation) or beautifulsoup4/scrapy.
Something like :
from selenium import webdriver
browser = webdriver.Firefox()
url = "https://www.target.com/"
browser.get(url)
# navigate to find your product
out_of_stock_text = "put your stuff here"
if out_of_stock_text in browsers.page_source:
# Do your stuff here
Good luck !

Python Selenium Recaphta I am not a robot - how to bypass

First of all, I am not by any means an expert scraping the web, selenium, or have a good understanding of html...
I am trying to download a CSV file that is hidden behind a 'recaptcha - i am not a robot'. I first must login to the website and then there is link that generates the I am not a robot captcha. It is the kind that you just click a box and must hit 'yes, i am not a robot' button.
I can't figure out how to get this to work. I've seen things about finding the x/y coordinates of where the box pops up and clicking, but I can't seem to figure that out. There seems potentially other methods, but I'm just having a hard time deciphering what to do and then how to do. My code thus far...
import selenium
browser = webdriver.Chrome()
browser.get("mywebsite")
username = browser.find_element_by_id("Email")
password = browser.find_element_by_id("Password")
username.send_keys('<<MY_EMAIL_FOR_LOGIN>>')
password.send_keys('<<MY_PASSWORD_FOR_LOGIN>>')
browser.find_element_by_xpath('//*[#id="container"]/div[3]/div[1]/div[1]/form/div[2]/div[2]/div[1]/input[6]').click() #button to 'login'
# so far so good - I am logged in!
elements = browser.find_element_by_id("patient-export-button")
elements
browser.execute_script("arguments[0].click();", elements)
# the lines above will cause the recaptcha popup to appear.
# now I am STUCK!
I have to now click the checkbox & hit 'yes' in order for my file to download. Sometimes when I hit the checkbox I get all these stupid 'find the car' images which are a pain in the ass for me to solve even as a human...
Any help on solving this recaptcha thing would be appreciated.

How can I press the Enter key on Selenium using Python without finding an element?

I am trying to enable the EasyPrivacy list on the AdBlockPlus plugin automatically using Selenium on Python.
On the website:
https://adblockplus.org/en/features#tracking
upon clicking on the `open this dialog' link, a window/popup/alert opens up, and all I want to do is press enter. However, I have not been able to find a way to send the Enter key without finding an element on the page. Since the window/popup/alert is not html, I cannot send the Enter key.
Any help would be appreciated
Hi after upon clicking on the `open this dialog' link, a window/popup/alert opens up do not try to hit ENTER button instead try to send TAB command via selenium and when tab control is at right place then use ENTER with selenium
hope this helps

Python, Selenium Webdriver: The element is not visible for Firefox.

I'm trying to iteract with a webelement on a page that has edit link that opens a popup. In opened popup I have simple input field and Apply/Cancel buttons. In my script I do the following to enter some text to the input field:
def enter_text(self, text, action):
if self.is_element_present(self._input_locator):
self.selenium.find_element(*self._input_locator).send_keys(text)
if action == 'Apply':
self.selenium.find_element(*self._apply_button_locator).click()
elif action == 'Cancel':
self.selenium.find_element(*self._cancel_button_locator).click()
When I run my script in Chrome - everything works fine, all webelements are found and input text is entered to the field. But when I run exact same script in Firefox - it opens popup window (which means it became visible for Webdriver) with input field and 2 buttons but the text is not getting entered to the field which causes error:
ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with'
Why can this happen if the popup is actually opened (and I can see it) but Webdriver tells that it is not visible? Also, I put several sleeps just to get sure that popup loaded and then the text is entered but it did not help.
Any help will be appreciated.
Two ideas:
1: make sure your HTML is valid, eg by running it thru the w3c validator. broken html is a common cause of different behaviours in different browsers.
2: have you definitely switched selenium over to the popup, using, eg:
for handle in self.selenium.window_handles:
# identify popup window's handle somehow
self.selenium.switch_to_window(handle)
As an aside, if you haven't come across selenium.implicitly_wait(3), it's dead useful as a way of avoiding time.sleeps and wait-for constructs..
Witch Firefox version and Webdriver version are you using?
Please try the following:
Update Webdriver to the last version
If you are using firefox 17-18, downgrade it to lower version (I guess FF12 will work)
Please try that and tell me what happens,
Regards

Categories

Resources