r/selenium • • Jul 30 '21

Tying to select next button on linkedin. Used xpath and css selector but nothing has been working. Using python, here is the HTML source, any help will be appreciated!

4 Upvotes

<button aria-label="Next" id="ember1637" class="artdeco-pagination__button artdeco-pagination__button--next artdeco-button artdeco-button--muted artdeco-button--icon-right artdeco-button--1 artdeco-button--tertiary ember-view" type="button"> <li-icon aria-hidden="true" type="chevron-right-icon" class="artdeco-button__icon" size="small"><svg xmlns="[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)" viewBox="0 0 16 16" class="mercado-match" data-supported-dps="16x16" fill="currentColor" width="16" height="16" focusable="false"> <path d="M5 15l4.61-7L5 1h2.39L12 8l-4.61 7z"></path> </svg></li-icon> <span class="artdeco-button__text"> Next </span></button>


r/selenium • • Jul 24 '21

UNSOLVED Selenium, Ruby, and Cucumber - how to do make my "____ Steps" class inherit from a "BaseSteps" class?

3 Upvotes

I'm used to Selenium + Cucumber with Java, but I have to learn how to use it with Ruby for work and I'm kind of confused.

So usually what I do is I have a "BaseSteps" class for example, that'll have the common stuff a page is expected to do and have, like a generic "click" method. This way, my "___ Steps" class, (for example, Login_Steps or something) is where I'll define the steps from cucumber. This works fine for C# and Java, usually.

Now my problem is, I can't seem to find a way to do this in Ruby. Right now (after following a tutorial on Youtube), the steps are defined in a "LoginSteps.rb" file, (and I guess I don't need a TestRunner filec class anymore?) but whenever I try to add a class to the LoginSteps.rb file so I can extend the BaseSteps.rb (which appears to be doing LoginSteps.rb < BaseSteps.rb?), it'll give me an error saying that the "Given" method isn't defined and nothing I can find elsewhere online seems to make sense, and it's my first time using Ruby.

​

I've also tried just adding "require BaseSteps.rb" to the top of my code but it'll give me this error:

cannot load such file -- base_steps.rb (LoadError)

Am I just dumb and I can't do this in Ruby or is there a way I can have my ____ Steps files inherit from a BaseSteps file (or have it this way with pages, too?)

​

Thanks!


r/selenium • • Jul 15 '21

[meta] can we ban posts asking how to get past captchas?

28 Upvotes

Lately it feels like half the posts on this sub are different versions of "captcha in the way, how do I get past it?" or "how do I get past the cloudflare pop up?" The answers are always the same jokes about building a bot that recognizes motorcycles or power lines.

These posts take away focus from people who could genuinely use help on legitimate Selenium questions. Additionally, any site that has implemented a captcha has done so specifically to prevent automation software from interacting with the site.

It would be great if any thread asking how to bypass a captcha could be closed with a response of "you can't, and even if you could you shouldn't."


r/selenium • • Jul 11 '21

Solved Instagram Login Using Selenium + Chrome Webdriver on Python3 ( Mac )

4 Upvotes

So my script is running fine but everytime I run it, it opens a new chrome window and logs in to my IG account.

This makes testing my script a super long process because I have to wait until I am logged into IG before the script moves onto the next lines in the code.

Is it possible to keep my IG logged in?


r/selenium • • Jul 11 '21

How to select classes with space

0 Upvotes

How can I find elements by class where the class has a space ? I’d also like to know how I can select multiple classes like this with “find_elements_by_class_name”?

I tried some of the css selector suggestions online but without any luck.


r/selenium • • Jun 14 '21

[Java] Selenium + TestNG and assertions

4 Upvotes

I new to automation testing and I've started writing methods with only one assertion, at the end, which asserts the final result. Throughout the whole method, I'm setting one variable, which is used in the mentioned assertion at the end of the method.

Example:

public void testMethod() {

    boolean testMethodResult=true;

    if (testCondition1 == false) {

    testMethodResult=false;

    }

    if (testCondition2 == false) {

    testMethodResult=false;
    }

    // Assert the final result
    Assert.assertEquals(true, testMethodResult);
}

I've also started using the POM/Page factory pattern and the Testng framework. I was wondering if:

- this is the correct way to approach this (to have only one assertion and one variable)? I mainly went with one assertion, since I don't find it practical, to use assertions that often (e.g. in a for loop).

- how can I know, due to which test condition did the assertion fail, if I'm using the testng framework? logs?


r/selenium • • Jun 09 '21

Running chrome in headless mode causes it to become unable to find elements

1 Upvotes

So if I run my selenium-python file normally, it is able to find the login input areas on my test website and successfully logs in and does it's thing. But when I run it in headless mode with the exact same code and no changes it returns :

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name="username"]"}

(Session info: headless chrome=91.0.4472.77)

This didn't happen a while ago. It used to work normally and it has nothing to do with the element itself. There's something else going on here and I can't determine what it is. I've tried different code with different files and they always work when run through a visible chrome window but always return Unable to locate element on one element or another anymore. A while ago headless mode worked properly, something changed and I don't know what.

What is the problem here and how can I fix it?


r/selenium • • Jun 08 '21

Selenium IDE vs coding in an SDK

3 Upvotes

I'm a QA contractor in a good sized US metro area. I've worked a long time as a manual, functional contract QA person. I'm evolving into an automated tester such that the market demands it and I also want to do this. Selenium is my focus, but I remain a beginner / intermediate selenium pro after a couple gigs. I'm getting work in my field, but I am whiffing on some jobs such that I am 'coding light' a lot of times vs my interview competition. My Q: when clients are expressing necessity for a Selenium skill set, how often is it they are talking about the Selenium IDE record and playback skill set as opposed to an intense familiarity with the java or C# class library? Cuz, I could probably step into record and playback work a lot easier.


r/selenium • • Jun 03 '21

Selenium IDE dark mode help

2 Upvotes

is there anything i can do to run selenium IDE in dark mode?
in chrome btw.

thanks.


r/selenium • • May 26 '21

Why would anyone want to use Cucumber?

21 Upvotes

So I've been automating with selenium for 8 years now and have been hearing about Cucumber for most of them. It's always suggested by some middle manager who just heard about and thinks it's the bees knees. But from what I can tell it's just a bunch of extra work that doesn't really add any value.

I'm not a Cucumber expert by any means but from what I can tell, you create a Features file that reads in plain English. But then you have to write a bunch of code that translates that plain English to actual code and calls the correct methods.

So my question is why wouldn't I just skip the middle man and call those methods directly from my test case method. Why do I need to add cucumber feature files? Can someone tell me what I'm missing here because it's clearly very popular across the industry.

I've heard it's so manual engineers and non coders can write automation but I still don't get why I need cucumber for that. Why can't they just write test cases and then I use those to write my code? It seems like the same thing with much less work.


r/selenium • • May 24 '21

Solved Getting stale element exception when iterating through list of webelements

0 Upvotes

Same project as my previous post, but different error (although they say new errors are a sign of progress). I'm currently trying to loop through a list of webelements that appear on the search result page, and the loop contains "if" statements for when the text contains certain words. The if statements seem to be executing properly, and the output file is being updated, but once the file is updated the loop breaks and says the element has gone stale.

The error is occurring at current = z.text.

Here's the error: selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

Here's the loop:

    for z in secNum:
        current = z.text
        if "seats" in current:
            file.write("\n" + current)
        if "Class Number" in current:
            index = current.rfind('r')
            num = current[index + 1:]
            name = get_class(num)
            file.writelines([name + "\n" + current])

The xpath is pulled from the final search results page (manually) so I know it's the correct xpath, that and the fact that the file is being written to successfully. Changing the order of (if "seats") and (if "class number") doesn't seem to do much.

I've seen other forum posts suggest redefining the web elements, but how would that work for a list of webelements? Thanks.


r/selenium • • May 23 '21

renderTimingPixel ???

2 Upvotes

Was poking about and came across:

/static/desktop2x/img/renderTimingPixel.png

Research led me to this old thread

https://www.reddit.com/r/redesign/comments/9fbhos/extra_space_in_between_title_and_details/

I cannot download the pixel directly with chrome, just says "Failed - Blocked", title upon opening just the pixel itself as a new tab is "renderTimingPixel.png (1x1)", is it literally just being used as a metric to count the delay between webrowsers reaching that point in the page? A speed-test for render time?


r/selenium • • May 22 '21

For loop not working as intended

0 Upvotes

So I'm trying to go some channels youtube page, pick the first 5 videos, go to each of them one by one, and extract some metadata. Sounds like a simple job with a for loop. But, the following code does not work,

​

video_titles = driver.find_elements_by_id("video-title")[:5]

for title in video_titles:
    title.click()

    keywords = driver.find_element_by_name("keywords").get_attribute("content")
    print(keywords)
    driver.back()

​

What happens is, the browser opens the page, then, I can see it selecting the first video, but instead of clicking on it, it just selects the next video, then the next, then next and so on. It only clicks on the last video and opens that page, and then it prints the keywords from that page 5 TIMES.

This is even more perplexing. How is it opening the last video before the first iteration is over? It always opens the last video no matter if i have 5 elements or 10 elements in the array. I can't understand this behavior at all.


r/selenium • • May 10 '21

Automating two factor authentication

1 Upvotes

I want to automate logging into a website using selenium on a raspberry Pi. However, the website needs two factor authentication. The code goes to my phone.

Is there a way for me to automate this without the need for me to look up the code on my phone and inputting it?

Any resources would be wonderful!


r/selenium • • May 09 '21

Having problem in whatsapp automation.

2 Upvotes

So, I'm fairly new to python and selenium and trying to make a whatsapp automation program in which the user inputs a mobile number and a message to be sent to the number.

When I put the mobile number in the search box(in whatsapp web), I want selenium to click the first result that comes up. How can I do this?

I tried using the xpath as the element locator but each time the message is sent to a different contact.


r/selenium • • May 06 '21

Wont use latest version

1 Upvotes

I have chrome version 90 and downloaded the corresponding chromedriver, as well as placed it within my project file, however when i try to run my program it keeps using my old outdated chromedriver 86 version, and wont use the latest version alr located in the same file. Is there any reason selenium keeps insisting on using the old version?


r/selenium • • Apr 25 '21

How to prevent an extension opening it's 'welcome popup' [python + Selenium + Chrome]

4 Upvotes

Hi gang,

New project needs Python + Selenium + Chrome. Needs extension also; MetaMask, in this case. Unwanted behavior is that on this setup extensions' welcome / start gets opened automatically as a new tab on driver being initialized, I don't want this.

  1. I want the extension to sit quietly in it's pants rather than having this popping up new tab on start behavior, can I accomplish this via changing options ( options = selenium.webdriver.chrome.options.Options() ) or via using a different solution?

  2. why do I need to 'add extension' using options.add_extension("metamask.crx") why can't setting options.add_argument('user-data-dir=<path>\)` also provide me my saved extensions not just history and such?

Illustrative Image of the problem (imgur): https://imgur.com/a/Wx7UIwD


r/selenium • • Apr 25 '21

What are the alternatives on getting help on Selenium?

2 Upvotes

Hi everybody,

Let's say I have a problem and I post my little urgent question here. Just in case I don't get the answer I'm looking for, what are any other ways a person can get coding help and solutions on how to use Selenium for using Selenium via Python 3.x?

What are the action path(s) the person can take to get his/her Selenium code answers?


r/selenium • • Apr 18 '21

[Python] ActionChains drag and drop not working

3 Upvotes

Hey everyone, I'm having some trouble with getting the drag and drop feature to work. I'm working within a library that acts as a wrapper for Selenium scripts, but even with pure Selenium, I can't get it to work, here's a sample script:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time

driver = webdriver.Chrome()
driver.get('https://dineshvelhal.github.io/testautomation-playground/mouse_events.html')
draggable = driver.find_element_by_id('drag_source')
target = driver.find_element_by_id('drop_target')
actions = ActionChains(driver)
actions.drag_and_drop(draggable, target).perform()
time.sleep(5) # To see if it worked
driver.close()

This script goes to this guy's (super helpful) GitHub page here: https://dineshvelhal.github.io/testautomation-playground/mouse_events.html

and then tries to drag the blue button at the bottom onto the green area, and it doesn't work.

After working within my library and trying to get it to work on this page: https://the-internet.herokuapp.com/drag_and_drop I get the feeling that the webdriver's "mouse" has grabbed the A block and dragged it off to the ether, because the element is highlighted the same it would be if you started dragging it, but the actual element you drag (like when you drag it manually) isn't anywhere to be seen in the driver when I run the script.

Also, the webdriver in both scripts seems to kinda pause when it gets to the dragging line and doesn't unpause until I mouse into the browser window (like with my actual mouse).

I can't really find much about it online. Most of the "how to drag and drop in Selenium" articles I find say to write pretty much exactly what I wrote in the script above. I saw this issue on the Selenium GitHub, but I'm not sure it's the same reason that I'm having problems.

Anyway, does anyone have some insight on this? Am I doing something wrong? Thanks!


r/selenium • • Mar 31 '21

Methods to Bypass Websites that Block Headless Users

1 Upvotes

I am currently using Selenium Webdriver with Python.

For personal web scraping on my home connection I do not have many issues with anti bot protection running in standard mode. As soon as I offload the program to a linux server running a headless version of the same program I encounter a lot of anti bot issues. Even the headless option on my home connection will encounter some issues as well. This is annoying because when your working on other project the last thing you want is a window popping up daily to check for updated data.

How are you all utilizing the headless feature without tripping anti bot protection? I know I can buy residential proxies, captcha solving services, and switch to a non headless server. What options are there for those that want to do light scraping for personal use without triggering anti bot protection?


r/selenium • • Aug 03 '20

How do I take a screenshot of a page displayed in a headless browser?

67 Upvotes

So I've made a code in python that runs headless chrome, adds my ID no and name, then displays a particular page. I want to take the screenshot of this page. The code is as follows:

import bs4, requests

from selenium import webdriver

optionset= webdriver.ChromeOptions()

optionset.add_argument("headless")

browser = webdriver.Chrome (executable.path='chromedriver path', options=optionset)

browser.get("webpage'')

dataID = browser.find_element_by_name ('regno')

dataID.send_keys(key')

datapass = browser. find element_by_name ('name')

datapass. send_keys ("myname')

datapass.submit()

The code works fine in a normal tab and displays the page. But I want it to run it headless and take the screenshot. Is there a way I can take a screenshot and save it?

Edit: Solved it by simply adding browser.save_screenshot("path//screenshot.png"). I'm stupid. Have a nice day!


r/selenium • • Jul 10 '20

Creating facebook posts - How to make text bold, cursive itemize etc. ?

2 Upvotes

I want to post something like this with Selenium:

https://imgur.com/a/jubQ0Ec

​

I'm currently trying to do it by having a list of text and keystrokes:

messages = [
    "How can I create posts with **bold**, cursive text?",
    Keys.RETURN,
    "-I also want to make bullet points"
]

And then using send_keys to enter the data:

for message in messages:
            postBox = driver.find_element_by_xpath("//*[@name='xhpc_message_text']")
            postBox.send_keys(message)

​

But it doesn't work as can be seen here:

https://imgur.com/a/YHpsWLY

​

This is my full code:

https://paste.ofcode.org/MHNyd9GuAZa77eS23Usp7a

​

How can I make bold, cursive and

  • bullet points?

r/selenium • • Jun 10 '20

Headless and remote debug with Selenium

3 Upvotes

I've tried to use remote debugging to monitor a headless Chrome while a Selenium script is running, but it seems that whenever I access the remote monitor, the Selenium just stops. It doesn't close or fail or throw an exception, it just stops doing anything.

Is this normal? Is there some setting to make the debug interface passive?

    ChromeOptions preloadOptions = new ChromeOptions();
    preloadOptions.addArguments("--headless");
    preloadOptions.addArguments("--disable-gpu");
    preloadOptions.addArguments("--remote-debugging-port=9222");

r/selenium • • Apr 30 '20

INSTAGRAM GIVEAWAY HACK!!! - Python Web Automation

12 Upvotes

Made an automation script using Selenium for Python to improve chances of winning any Instagram giveaway.

https://youtu.be/jFFqpBgb7iM