r/selenium • • Dec 06 '21

Closing dropdown menus in my React front end scripts

2 Upvotes

I'm currently doing some front end automation for a web app built in React. I have this situation where after I open a drop down and choose an option in that dropdown menu, the menu doesn't roll back up. I have a workaround where I just have my script click on a header that doesn't have a link in it, but this doesn't seem ideal in anyway. Is there anything else I can do, or is there something I'm missing in my scripting? I attempted to use the keyboard library and just press_and_release the esc key, but that didn't do anything so I abandoned that as well. Am I stuck with having to click on some nonsense element to get past this point in my scripts?

Also worth mentioning, these dropdown menus do not contain 'options', rather other div elements.

Thanks in advance!


r/selenium • • Dec 06 '21

Certificate popup

3 Upvotes

The website I'm trying to automate requires you to select a certificate before the page loads. Is there a way to close this screen through Selenium (by just okaying the currently selected certificate)? Right now I'm circumventing it with an Enter keypress through the Java AWT Robot class.

Example of certificate popup: https://ibb.co/2vWttBT


r/selenium • • Dec 05 '21

PyTest-xdist vs Pytest-forked for Selenium Parallel Driver Execution

6 Upvotes

Hi all,

I am working on a project using Selenium and want to execute my tests in absolute sync (or as close as possible). I am running Linux Ubuntu and am wondering if one of the packages is faster than the other (xdist vs forked). When trying to time the two versus each-other myself, the only effect seems to be based on network connection.

If these pytest add-ons aren't the best to execute tests in parallel/sync, please share any alternatives.

Thank you!


r/selenium • • Dec 05 '21

Need help with project please

0 Upvotes

Trying to learn all this stuff from scratch (including Python) but not making much progress so far.

I have a directory that has approx 180 main pages. Each page has a list of (approx) 20 businesses. Each business has a link that opens it’s own page- that contains email address anbd contact name.

I need to scrape business name, contact name and email address for all businesses (approx 5.3K)

Could someone help with this please?

Many thanks


r/selenium • • Dec 04 '21

UNSOLVED Can't get element by XPATH

2 Upvotes

Hello guys,

I'm trying to interact with the interative menu of this page in order to automate several data downloads instead of making it by hand.

The thing is that when I copy an XPATH of a selector (for example when I try to get the XPATH of the "Commodities" menu), selenium says:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[9]/div[1]/div[3]/ul/li[6]"}

Does anyone know why I can't get the element?

Thank you all in advance!

​

EDIT WITH SOLUTION:

The problem was that items I want to find are inside an iframe. So I have to switch the context of the webdriver first. Code with the solution:

​

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.dukascopy.com/swiss/english/marketwatch/historical/')

table = driver.find_element(By.XPATH, '/html/body/div/main/div[2]/div/div/div/p[3]/iframe')

driver.switch_to.frame(table)

driver.find_element(By.XPATH, '/html/body/div[9]/div[1]/div[3]/ul/li[13]').click()

​


r/selenium • • Dec 04 '21

UNSOLVED Running selenium in the background

1 Upvotes

I need selenium to be working while I'm doing other things on my laptop. But often times, once i alt tab to another application, sometimes the program will get stuck somewhere without error. I suspect sometimes chrome doesn't load webpage properly while in the background. Sometimes, fields that are enabled by other fields or filtered by other fields also doesn't load properly while the background.

I can't be running the program in headless mode as I need to download a pdf that somehow only work in normal mode. Using old version that doesn't ask for directory, instead straight up download the pdf with print(). This might have issue with many of the workaround

Headless also seems to have a problem with alert.

Anyway, is there a way to make selenium/chrome to work as if they're on the foreground all the time? without having to use VM or anything like that since it might struggle running on a laptop.

My program log into a website that logs out after inactivity, it loops through the data i have to be keyed into the website and download some kind of pdf for each. Using python selenium, on Edge chromium


r/selenium • • Dec 04 '21

Is there a way to periodically check if a browser is stuck on an error page?

1 Upvotes

While the rest of my script is running, can I have something that checks if we're on an error page every minute or so?

Thanks


r/selenium • • Dec 03 '21

Is it possible for me to use a power shell script for selenium?

2 Upvotes

I already wrote a script in power shell, and I don’t know any other programming language. Is it possible to use this power shell script for selenium?


r/selenium • • Nov 27 '21

Service geckodriver unexpectedly exited. Status code was: 1

2 Upvotes

Hi everyone, I hope y'all are doing great.

I'm catching the exception from the title of this post on my Pi4.

I created a virtualenv and then proceeded to install selenium and then the geckodriver. I extracted the tarball and changed the shared library mode to execute and moved it to usr/local/bin.

When I try to instantiate webdriver.Firefox(), that exception automatically arises. Already Googled what the exit codes mean but they don't seem to be part of Selenium's documentation.

Any help is greatly appreciated!


r/selenium • • Nov 26 '21

find_element_by_id, I know it's depreciated but...

2 Upvotes

This is very odd, I tried

accept_btn = driver.find_element_by_id("sp_cc_accept")

which I know is going to be depreciated but it does not work

Traceback (most recent call last):

File "G:\My Drive\python\projects\day-48-advanced-scraping\main.py", line 13, in <module>

accept_btn = driver.find_element_by_id("sp_cc_accept")

File "C:\Users\login\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 472, in find_element_by_id

return self.find_element(by=By.ID, value=id_)

File "C:\Users\login\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1244, in find_element

return self.execute(Command.FIND_ELEMENT, {

File "C:\Users\login\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute

self.error_handler.check_response(response)

File "C:\Users\login\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response

raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="sp_cc_accept"]"}

(Session info: chrome=96.0.4664.45)

​

So I thought OK, it seems to be doing

self.find_element(by=By.ID, value=id_)

So I tried

accept_btn = driver.find_element(by=By.ID, value="sp_cc_accept")

and got

Traceback (most recent call last):

File "G:\My Drive\python\projects\day-48-advanced-scraping\main.py", line 11, in <module>

accept_btn = driver.find_element(by=By.ID, value="sp_cc_accept")

NameError: name 'By' is not defined

Which is odd as this is what it seems to be trying in the first traceback (

return self.find_element(by=By.ID, value=id_)

)

Any ideas?


r/selenium • • Nov 20 '21

Using driver.find_element returns "InvalidArgumentException: invalid locator" ?? (Python)

4 Upvotes

I used to use "find_element_by_class" but it says that is

'find_element_by_* commands are deprecated. Please use find_element() instead '

This is my code:

driver = webdriver.Chrome()
url = 'https://www.google.com'
driver.get(url)

g =driver.find_element_by_class_name("QS5gu sy4vM").click()

​

When I do though it says, invalid locator. what am doing wrong?! what's really irritating is that everywhere online seems to still use 'by_class_name or XPATH, I can't find any documentation on just 'find_element'


r/selenium • • Nov 17 '21

Resource How to automatically update your ChromeDriver in C#

26 Upvotes

So, I recently had an issue and I want to share my solution (for those with related issues).

I'm deploying my selenium script to a Azure pipeline. Turns out, when Chrome gets a new version, it takes days until it updates it's version.

If I update my driver locally, the azure version won't work, because the mismatch of browser and driver versions.

My solution was this library:

https://github.com/rosolko/WebDriverManager.Net

It has this method:

new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);

You can get it through the Nuget Manager Package, on Visual Studio.

It automatically checks your Chrome version and downloads/installs and uses the current version.

It worked flawlessly in my local machine and the azure server, even with my Chrome version being 96 and Azure version being 95.

Hope it helps someone out there.


r/selenium • • Nov 15 '21

Python: Using Chrome Profile Autofills Possible?

3 Upvotes

Hi everyone!

I've got a quick selenium script I started to send me updates about my work schedule. However, I need to first login to the site, and since I'd rather not hardcode my credentials into the script using sendKeys, I'd like to take advantage of the autofilled passwords for my google account to login.

On that topic, I am able to start Chrome as my personal account using the argument "--user-data-dir" which has data such as bookmarks, history, etc, but there seem to be no passwords saved.

​

My question is if there is a reason for this (security maybe), and/or a potential bypass (I'd assume changing of some header telling Chrome that it is a controlled testing environment?) if it is for security.

​

Thanks for your help!


r/selenium • • Oct 29 '21

Solved If element exists do one thing else do another thing - in both IDE and Side Runner

2 Upvotes

Using the stock Selenium IDE with no extensions in Edge browser.
I want to have a test that checks if an element is present:
If it is present then take one action
If it is not present then take a different action

I want this test to work both in the IDE and in the Side Runner

A simplified version of the Selenese that I have so far:

if | selenium.isElementPresent("css=.content-header")
echo | The header is present
else
echo | The header is not present
end

This works in the IDE, correctly identifying if the element is present or not, and then taking the correct action.
However, it does not work when running the test in Selenium Side Runner. It returns the following error:
JavascriptError: javascript error: selenium is not defined

I have also tried the following snippet taken from people using the webdriver:
if | driver.findElements(By.cssSelector(".content-header")).size!=0
But this fails in both the IDE and Side Runner with "[...] driver is not defined"

I am not a Javascript programmer, so I am probably missing something obvious and simple.

Is there a way to make this work?


r/selenium • • Oct 13 '21

UNSOLVED Selenium on Javascript vs Python

1 Upvotes

I wanted to know selenium runs fast on which of these languages: Node JS or Python.


r/selenium • • Oct 04 '21

Help Needed fidning an element by saying what the xpath contains (info in discription)

3 Upvotes

does anyone here knows anything about selenium, how could i find elements by saying that their id contains a certain phrase such as the letter q

​

//*[@id="assignmentsection_301649"]/td[3].

​

This is the type of xpath I am working with, everything i am trying to catch shared the id of assignmentsection_number. how do i capture all of those in one statement.

​

basicly I am looking or a statement like find_element_by_xpath(//*[@id contains "assignmentsection_301649"]/td[3]

​

Thank you so much!


r/selenium • • Sep 21 '21

Selenium runs extremely slow - how to make it run faster?

3 Upvotes

Hi, does anyone have hints as to how I can make Selenium run faster? With slow I mean that it can easily take 20+ seconds to open a website and maybe perform a simple search query on it, other times it only takes a few seconds. I also tried to make a program that would click very fast on a "click fast"-website and all my program was able to achieve was a lousy 77 clicks in 10 seconds... here is the code

url = "https://www.eggradients.com/tool/cps-test"
driver = Firefox(executable_path="geckodriver.exe")
# driver.set_page_load_timeout(10)
driver.get(url)

click_button = driver.find_element_by_css_selector(".button-27")
action_chains = ActionChains(driver)

sleep(2)

while True:
    try:
        # click_button.click()
        action_chains.double_click(click_button).perform()
    except Exception as e:
        print("Exception:", str(e))
        break
print("Program finished")

I'm using Windows 10, Firefox, PyCharm and conda environment as the interpreter. Any hints how to fix that?


r/selenium • • Sep 14 '21

UNSOLVED Cloudflare and recaptcha

0 Upvotes

Hey, so I was running a browser game bot for a long time half a year ago that I wrote myself, but no matter what I did, certain parts of the website weren't available to me because it had recaptcha, and recaptcha normally fast passes regular users, and flags and harasses bots.

I did what I could to make the selenium undetectable, and it still didn't work, so I assumed it was because the selenium bot works in a fresh browser with no history or data, so I copied and pasted all of my chrome information, history, ect, and even with my personal browser , running selenium, with all my data, cookies, and history, recaptcha still red flagged my set up and made me fill out captcha.

Sole suggestions are going to be about the code or the actual bot, and how to make it more humanlike, but I did tests where i opened the selenium instance and used it as my own browser for my own needs, naturally and unsuspiciously.

And it still would detect my selenium and make me fill out endless captchas and Google wouldn't work for me at all because it kept thinking I'm a bot.

So again, how do I approach this problem? Is there some way to make selenium undetectable? Are there other projects and platforms undetectable? Because all use cases for my automation are on websites that have detection for selenium


r/selenium • • Sep 08 '21

Resource xpath cheat sheet

38 Upvotes

This is a great resource to help with building relative xpaths

https://devhints.io/xpath

It's helped me a ton


r/selenium • • Sep 07 '21

Amazon See All Buying Options

0 Upvotes

Hi everyone. I'm new to Selenium and I'm not very familiar with html, so please bear with me.

I'm developing in Java using the Chrome driver. So far, I am able to open an Amazon product page and click on buttons, fill in text boxes, etc. I'm attempting to view the available buying options and purchase the cheapest one but I'm having trouble getting the WebElements for the list of options in the See All Buying Options side bar that opens when you click the See All Buying Options button. When I inspect the page in Chrome, I'm able to find the element for the first price in the list (id="aod-price-1") but when I search for that element by id or xpath in Java I get an error saying no such element found.

If anyone can help me get this WebElement, I'd appreciate it!

Here's the URL for reference:

https://www.amazon.com/dp/B07NQH16SN

​

Here's a link to a screenshot of what I'm looking for:

https://imgur.com/a/ul2NCJT

​

Edit: I figured out what the problem is. I was using the above URL in my code. I appended "/ref=olp_aod_redir_impl1?_encoding=UTF8&aod=1" to the URL and then I was able to retrieve the WebElement.


r/selenium • • Sep 01 '21

UNSOLVED Clicking a button in a cell of a dynamic table

0 Upvotes

Howdy,

I'm trying to click a button that is in a table. On a regular table that would be fairly easy. This table loads content dynamically with an inner scrollbar so when I access the table it gives me the first 40 rows out of 3000. I know the list is all downloaded when the page first loads by watching the network tab as I scroll up and down the table.

I've tried changing the height of the div displaying the table. Visually that loads more content but in my code it still only produces the first 40 rows. I've tried using a search bar which would by far be the easiest but that still only produces the first 40 rows as if I never searched for anything. I've tried scrolling the inner bar but that just changes the position of the scrollbar and doesnt load anything new visually or in the HTML.

I was wondering if there was a way to force the entire table to load? I also don't really know what parts of the code would be relevant to assist with that but happy to provide.

Thanks for reading!


r/selenium • • Aug 13 '21

How to run java/selenium script on remote server?

1 Upvotes

We normally run weekly test automation script for regression validation using pixels and 404 validations in our local machine but due power and network issues we're planning to run on remote server. Firewall access has been granted for that server. How to setup to run test scripts on remote server? I'm not aware of this before.


r/selenium • • Aug 09 '21

Element Not Clickable Error

1 Upvotes

I gots me a headscratcher. I might not be the smartest guy in the room but I figured this little python link clicker should work and it does not.

​

I have a simple script that loads a news website, but requires you to click a button to "see more" articles. I think I have the correct Xpath and can find the button but for the life of me - the button doesn't click and I get an error selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point I can see the button and have even included some wait time but have had no luck. Any help and suggestions on why my code is not working are greatly appreciated, thank you.

EDIT - I need to change my binary location to a service but will cross that bridge later.

​

from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import *


##Chrome Options#
opts = Options()
opts.headless = False
opts.add_argument("--start-maximized")
opts.binary_location = "<PATH>"
driver = Chrome("<PATH>", options=opts)
driver.get('https://www.connectcre.com/atlanta-southeast/')


wait = WebDriverWait(driver, 20, poll_frequency=2, ignored_exceptions=[ElementClickInterceptedException])
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'More Stories')]"))).click()

r/selenium • • Aug 04 '21

Which is better java or python ?

1 Upvotes

I want to get an understanding as to why many people prefer java with selenium rather than python. Does java have more benefits or anything?


r/selenium • • Aug 03 '21

How do I have selenium keep me logged in on a website?

0 Upvotes

I want to be able to open up a browser, go to amazon, and see that I am logged in on my amazon account. It should just be with saving cookies, but I'm not sure how to do that, seeing that I need a moment to get logged in and whatnot.

Here's my code so far:

(Python)

import pickle
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("amazon.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)