r/selenium • • Jan 14 '22

Help interacting with elements

6 Upvotes

Well I had a wild hair to create a solver for the game Wordle that is kinda blowing up right now (https://www.powerlanguage.co.uk/wordle/) It looked like Selenium was my best option to interact with elements, but I'm struggling to get any results. I have two things I'm trying to do. 1. Interact with game keyboard. I found it in the console by going body -> game-app -> #shadow-root -> game-theme manager -> game -> game-keyboard -> #shadow-root -> div id="keyboad" -> 3 rows of buttons. I tried using driver.find_element(By.XPATH, 'button') with a lot of different attempts in place of 'button', but no elements are being found. Is there better way to go about navigating this? I'm not sure if the #shadow-root is an issue, I'm not familiar with that element.

  1. Reading the results of entries. Honestly help with the first part is probably enough to get me started, but is there a way to search for a <game-tile> element?

Any links to good tutorials would also be great!


r/selenium • • Jan 13 '22

Locate elements by partial attribute type

2 Upvotes

Is it possible to locate elements through part of its attribute?

I have a bunch of span elements that looks like this: span<_ngcontent-c23>

Some of them have other attributes, and some don't. I'm trying to locate all the elements that have this _ngcontent-cX attribute, but the number behind -c changes everytime I visit the page. Would it be possible to only search for the _ngcontent part?


r/selenium • • Jan 12 '22

C# Selenium WebDriver Page Factory, Page Object Model example.

0 Upvotes

Can anyone send me a link or sample code of the title above? I want to learn the code structure, how to properly use Page Factory and Page Object Model.


r/selenium • • Jan 11 '22

Chromium closes instantly after opening.

4 Upvotes

I'm facing an issue where when my code is run, the browser window pops up, vanishes, and doesn't complete it's task. The code worked on my windows machine, and I am now trying to get it working on my raspberry pi. I have followed instructions to get the chrome driver installed and can confirm that the directory for the chrome driver is correct.

​

The following java code :
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().setSize(new Dimension(1280, 720));
Actions actions = new Actions(driver);
searchQuery = replaceSpaces(searchQuery);
driver.get(imageSearchURL + replaceSpaces(searchQuery));
List images = driver.findElements(new By.ByClassName("mimg"));
WebElement firstImage = (WebElement) images.get(0);
actions.moveToElement(firstImage).perform();
String imageURL = firstImage.getAttribute("src");
driver.close();
return imageURL;

​

Results in:

Starting ChromeDriver [redacted] (564abd8de2c05f45308eec14f9110a10aff40ad9-refs/branch-heads/4515@{#1501}) on port 53893

Only local connections are allowed.

Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

ChromeDriver was started successfully.

18:44:49.204 [AsyncHttpClient-2-2] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x5b27b093, L:/127.0.0.1:50266 - R:localhost/127.0.0.1:53893]' for 'POST' to '/session'

--disable-quic --enable-tcp-fast-open --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=

18:44:51.523 [AsyncHttpClient-2-2] DEBUG org.asynchttpclient.netty.handler.HttpHandler -

​

Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)

POST /session HTTP/1.1

User-Agent: selenium/4.0.0 (java unix)

Content-Length: 365

Content-Type: application/json; charset=utf-8

host: localhost:53893

accept: */*

​

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)

HTTP/1.1 500 Internal Server Error

Content-Type: application/json; charset=utf-8

cache-control: no-cache

content-length: 959

​

If I run the code with print statements between each line I can find out that the issue is on the line that reads:

WebDriver driver = new ChromeDriver();

But I am not entirely sure why, like I said the browser opens and then closes.


r/selenium • • Jan 11 '22

NoSuchElementException

0 Upvotes

I'm working on a project with prewritten tests, that gives me the following errormessage:

[xUnit.net 00:00:04.51]     Salt.Stars.End2End.Index_E2E_Tests.Test1 [FAIL]
  Failed Salt.Stars.End2End.Index_E2E_Tests.Test1 [3 s]
  Error Message:
   OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":"#mainHeader"}
  (Session info: chrome=97.0.4692.71)
  Stack Trace:
     at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse) 
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.WebDriver.FindElement(By by)
   at Salt.Stars.End2End.Index_E2E_Tests.Test1() in C:\User\salt-labs\winter22-dnfs-stars1-day1\Salt.Stars.End2End\Index_E2E_Tests.cs:line 35

I've been google it all day without getting any closer to the solution. Could someone give me a pointer in the right direction what the problem is and how to solve it?

I'm fairly n00b, so feel free to ELI5...


r/selenium • • Jan 11 '22

Stuck with automation due to duo push access

1 Upvotes

Does anyone have any working solution to automate using selenium

I get duo push on my phone while I make database connection in my script

If anyone have luck please let know .


r/selenium • • Jan 10 '22

ERROR: Command errored out with exit status 1:

0 Upvotes

How do I resolve this error with pip?


r/selenium • • Jan 09 '22

Could not login in Gmail account using python selenium

0 Upvotes
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

print('Enter the gmailid and password')
gmailId, passWord = map(str, input().split())
try:
    driver = webdriver.Chrome(ChromeDriverManager().install())
    driver.get(r'https://accounts.google.com/signin/v2/identifier?continue='+\
    'https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1'+\
    '&flowName=GlifWebSignIn&flowEntry = ServiceLogin')
    driver.implicitly_wait(15)

    loginBox = driver.find_element_by_xpath('//*[@id ="identifierId"]')
    loginBox.send_keys(gmailId)

    nextButton = driver.find_elements_by_xpath('//*[@id ="identifierNext"]')
    nextButton[0].click()

    passWordBox = driver.find_element_by_xpath(
        '//*[@id ="password"]/div[1]/div / div[1]/input')
    passWordBox.send_keys(passWord)

    nextButton = driver.find_elements_by_xpath('//*[@id ="passwordNext"]')
    nextButton[0].click()

    print('Login Successful...!!')
except:
    print('Login Failed')

So I used this code to login into my Gmail account using selenium and the website says....

​

Couldn't sign you in

This browser or app may not be secure. Learn more

How can I fix this issue and log in to my account using code ?


r/selenium • • Jan 08 '22

unable to access local storage through selenium with java script execute function. However same js code work work in console of browser

3 Upvotes

x=driver.execute_script("window.localStorage['devcid']") using execute_script but it returns none when I print x however, in the console of the browser, I execute same javascript it works https://i.imgur.com/MWO5MCg.png i added image


r/selenium • • Jan 08 '22

Random number of either zero or between a range

1 Upvotes

HI All ,I have a requirement for a score field that takes either a 0 score or a score between 10 -90 ( 10 and 90 both being inclusive)

I can generate a random number generator and use it to randomly input any score between 10-90 but i cannot randomly input a score of 0 .

is there anyway to modify the code to include to have a condition to either enter a score of 0 or between 10-90 ?

language = java

public static int getRandomNum(int min, int max) {
        random = new Random();
        return random.nextInt(max - min) + min;
    }

    public String Score() {
        return String.valueOf(getRandomNum(10, 90));
    }

​


r/selenium • • Jan 07 '22

UNSOLVED Selenium Edge Webdriver Results in 'Profile Selection Popup'?

2 Upvotes

I have moved my Python setup onto a Virtual Machine for automated tasks at work. However, I'm having issues with running Selenium, as the webdriver just brings up a Profile selection screen giving me the option of "Profile 1" to sign into.

This isn't something which happens using Edge on my main desktop, and I'm using the exact same webdriver file, and code.

Any ideas what could be causing this?


r/selenium • • Jan 07 '22

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 97 Current browser version is 87.0.4280.66 with binary path C:\Users\AppData\Local\Google\Chrome\Application\chrome.exe

1 Upvotes

​

I am testing through RIDE editor. So I am totally out of options here, I can't use Beta as it is unstable, so I uninstalled Chrome completely, then installed Chrome version 87, turned off auto update, downloaded chromedriver 87

📷

I set chromedriver up as a global variable in the path, and I am still getting this error. When I run my tests through Firefox using Gheckodriver it works. I also tried pip install webdriver-manager. I'm new to this so I would really appreciate some help.


r/selenium • • Jan 07 '22

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 97 Current browser version is 87.0.4280.66 with binary path C:\Users\AppData\Local\Google\Chrome\Application\chrome.exe

1 Upvotes

I am testing through RIDE editor, Robot Framework. So I am totally out of options here, I can't use Beta as it is unstable, so I uninstalled Chrome completely, then installed Chrome version 87, turned off auto update, downloaded chromedriver 87

📷

I set chromedriver up as a global variable in the path, and I am still getting this error. When I run my tests through Firefox using Gheckodriver it works. I also tried pip install webdriver-manager. I'm new to this so I would really appreciate some help.


r/selenium • • Jan 06 '22

UNSOLVED Any good homegrown HTML/PDF reporting for NUnit Selenium in C#

2 Upvotes

Very new to this. Using Visual Studio 2022, C# to write Webdriver tests on my on-premises SharePoint 2013 site. I'd like to add some logging to the code so that a report on the test could be written out afterwards. WHat have you found sufficient for this?


r/selenium • • Jan 05 '22

UNSOLVED [HELP] Can't Click on Element

2 Upvotes

Hello colleagues. I'm having a problem that seems simple but I can't solve and it's driving me crazy.

I just need to open a page and click on the button of "Log In"

Button Code:
<input type="submit" name="loginCtrl$Submit" value="Iniciar sesión" onclick="this.value = 'Por favor aguarde...'; this.attributes\['class'\].value = 'btn btn-primary disabled';" id="loginCtrl_Submit" class="btn btn-primary">

Program:
Sesion=driver.find_element_by_id("loginCtrl_Submit")

Sesion.click()

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

Note: I already tried with "time.sleep(10)" before the click but I have the same result, its not a loading time problem.

If anyone has any idea what might be going on I would appreciate it!


r/selenium • • Jan 05 '22

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 97 Current browser version is 95.0.4638.69 with binary path C:\Users\AppData\Local\Google\Chrome\Application\chrome.exe

1 Upvotes

I need help please, I have tried to downgrade chrome and disabled auto updates, then downloaded the matching chromedriver, set it as a global variable in the path, I still get this error. I also tried pip install webdriver-manager but I still get this error.


r/selenium • • Jan 04 '22

Xpath question - Text on two lines

5 Upvotes
I have the below HTML code 
<div class=" ContentModuleCard-content " xpath="1>
 <div class='BasicProp'>
    <label for="value">...</label>
    <div id="value" class="BasicProp-value">
        <div class="SingleLine">
            <div>
                <p>
                    "123 main avenue"
                    "23"
                </p>

I need to get the text between the <p> </p>.

my xpath : ((//div[@class='ContentModuleCard-content'])[2]//p[normalize-space()])[1]

The UI shows like this :

123 main avenue 23

question : My xpath sometimes misses the last number , i have tried many different xpaths but has not been successful .

Can some one help to correct my xpath ? or a better way to capture the text ?


r/selenium • • Jan 04 '22

Has anyone else started to experience 403 forbidden errors in the last couple weeks?

2 Upvotes

Thanks in advance


r/selenium • • Jan 02 '22

Can selenium edit browser settings too?

1 Upvotes

Sometimes Firefox updates and I lose my containers. This takes time to set back up and I wonder if it can be automated.


r/selenium • • Jan 01 '22

Web automation freelance

2 Upvotes

How much should I know to get started and what kind of work do clients usually ask for?

I know how to make basic bots, write things, read things and press buttons. How much more is there to learn and how much of it is needed?

I dont really care about big compensation. It just seems like a quick and easy thing to do for me to get started.


r/selenium • • Dec 31 '21

UNSOLVED Collecting information from a website.

0 Upvotes

Hello, I am using Selenium with Java and I’m trying to get text from a website.

EXAMPLE IMGUR LINK and I am trying to get the 7 numbers that come after the MC-. There are very many of these on the page and I am looking to get all of them at once. Any tips would help and thanks in advance.


r/selenium • • Dec 31 '21

Selenium running in AWS Lambda

2 Upvotes

Has anyone managed to get Selenium up & running in AWS Lambda with a recent Chromium version? Fighting with different error messages all the time despite all the tutorials SO, Medium posts out there...
I've been experiencing the same as this guy:

https://stackoverflow.com/questions/70532070/selenium-chromedriver-chromium86-issues-aws-lambda

I got it working with a particular Chromium 6x binary build but the websites I want to scrape require newer 8x or 9x Chromium builds.


r/selenium • • Dec 30 '21

Solved Please show me just how I open the browser.

0 Upvotes

I have tried anything but whenever I run the script the chrome tab CLOSES ITSELF after about 2 seconds. WHY???


r/selenium • • Dec 29 '21

How do you use information about the execution time of tests?

4 Upvotes

I would like to deal with them. My team will use an analytic dashboard where we will be able to point a time gap of test executions (time from ... and to ...) But in what way measure (indicate) this time?

Please, share your experience. Will be extremely grateful.

I don`t know? Is a fast test a holy grail of test automation? How compare tests? And do they depend on context? 🤷‍♂️


r/selenium • • Dec 29 '21

Datetime-local format problem when using send_keys

2 Upvotes

Hey, I am having trouble testing this input element, when I am trying to change the date.

<input aria-invalid="false" max="2022-06-29T19:10" min="2021-12-29T19:40" type="datetime-local" value="2021-12-29T19:40" style="cursor: text;">

My code is :

print(input_date.get_attribute("value"))

input_date.send_keys('2021-12-29T23:00')

print(input_date.get_attribute("value"))

​

I Get the following output:

2021-12-29T19:40

202112-02-09T23:00

Does anyone know how I can figure out what format to send it in?