Is there a potential security measure that can deactivate automation processes?

I'm currently developing a Python script using the Selenium Chrome Webdriver to automate tasks on this specific Swedish website: .

My main focus is automating the login process, however I have encountered some persistent errors such as:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

and

Keyboard not reachable

In my script, I am attempting to locate both the email input field and password input field with the following code:

emailInp = driver.find_element(By.XPATH, '//*[@id="UserName"]').send_keys('test')
passwordInp = driver.find_element(By.XPATH, '//*[@id="Password"]').send_keys('123')

I've experimented with various options settings, implemented the WebDriverWait function, and even switched browsers to Firefox and Safari, but unfortunately none of these attempts have proven successful.

I'm beginning to consider the possibility that the website may have security measures in place to prevent automation scripts. If this is the case, I am curious if there are any workarounds available to bypass these restrictions?

Answer №1

You have encountered the issue of using non-unique locators. It seems that there are 3 elements matching the //*[@id="UserName"] and //*[@id="Password"] locators.
It is crucial for locators to be unique at all times. To resolve this, you should consider the unique parent element in order to make the locators distinct.
You can refer to the following code snippet for a working solution:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://nordicwellness.se/logga-in/?redirecturl=/mina-sidor/"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.XPATH, "//main//input[@id='UserName']"))).send_keys('test')
wait.until(EC.element_to_be_clickable((By.XPATH, "//main//input[@id='Password']"))).send_keys('123')

A screenshot of the result can be viewed here:

https://i.stack.imgur.com/BySaI.png

Answer №2

Upon reviewing your XPath, it appears that the issue may stem from how Selenium is interacting with the web elements on the page. The XPath you have specified, //*[@id="UserName"], actually matches 3 elements on the webpage. By default, Selenium will interact with the first matching element, which in this case may be hidden within the top menu resulting in the "element not interactable" error.

To resolve this, one solution is to use the full direct XPath as shown below :

emailInp = driver.find_element(By.XPATH, '/html/body/div[1]/main/div/div/div/form/input[1]').send_keys('test')
passwordInp = driver.find_element(By.XPATH, '/html/body/div[1]/main/div/div/div/form/input[2]').send_keys('123')

Alternatively, you can specify the exact //*[@id="UserName"] element you wish to access, for example:

emailInp = driver.find_element(By.XPATH, '//main//*[@id="UserName"]').send_keys('test')
passwordInp = driver.find_element(By.XPATH, '//main//*[@id="Password"]').send_keys('123')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a flaw in the Django migrations build_graph function?

Upon running my tests after squashing migrations, an error report is generated: lib/python2.7/site-packages/django/db/migrations/loader.py:220: KeyError The source code causing the issue is as follows: def build_graph(self): """ Builds a mig ...

I'm currently struggling with some code that's not giving me the desired output. Is there a way you could suggest to help me scrape text from Facebook comments on a live stream or post?

I am interested in scraping Facebook comments from FB Live or posts. Does anyone know of a way to do this? If so, please provide assistance. I have attempted the following code without success: comments = driver.find_elements_by_css_selector('.UFICo ...

Python fastAPI and MongoDB environment allows the return of a tuple in the BaseModel list

Currently, my setup includes env with python311, pydantic, fastapi, and mongod. return membercollection(members=await c_members.find(queryparam).to_list(1000)) This code snippet retrieves the following information: members=[membermodel(id='65b3908a77 ...

Creating a table of contents using PyPDF2 in Python is a great way

I've had success using PyPDF2 for combining PDFs and adding bookmarks. Could PyPDF2 also be used to include a hyperlinked table of contents page in the merged file? Thank you for your response. While I can generate a ToC based on your suggestion and ...

Selenium - Element not located using xpath

Searching for a particular element in this webpage, specifically the bid price in the initial row: 196.20p. Utilizing selenium, here is the code I am using: from selenium import webdriver driver = webdriver.PhantomJS() address = 'https://www.trustne ...

What is the most effective method for locating every .mp3 file on a device?

Is the os.walk() method simple to use but too time-consuming when scanning through all files? Are there alternative methods that are faster and require less processing power? I've experimented with both the os.walk() and glob() methods, however, glo ...

Retrieving HTML content of a scrolled page using Selenium

I am a beginner with Selenium and currently attempting to scroll to the bottom of Twitter profiles in order to access all tweets for web scraping. My goal is to retrieve the HTML content of the fully scrolled page, but I encountered an issue while trying t ...

Unexpected behavior when using multiple values with Pandas apply method

When attempting to utilize a function that returns a tuple of values with the dataframe 'apply' function to populate multiple columns simultaneously, an unexpected outcome occurred. The following code snippet demonstrates this issue: df = pd.Dat ...

Adding additional keywords to the header of a fits file using astropy's io module

I've been attempting to add new cards to the primary header of an existing FITS file. Despite receiving a 'successful' message in the terminal, when I view the header info in DS9, my new card is not displayed. It seems like my changes are no ...

Build server running Windows 2012 R2 with IE 11 Selenium experiencing an UnexpectedJavaScriptError

Currently, I am developing automation tests using C# and .NET 4.5 along with SpecFlow + NUnit. In my ASP.NET MVC project, I am utilizing Kendo MVC controls. There is a specific page where we use a JavaScript variable to signify that all client-side Kendo ...

When a function is called within a 'For' loop, it may result in a NameError

I've encountered an issue while attempting to call a function from within a FOR loop. The error message I receive is: test() NameError: name 'test' is not defined Below is the code in question: from selenium import webdriver from seleni ...

Pause for a specified duration to wait for an element

I am currently facing a challenge with test automation implementation. Specifically, my test is checking for the display of a hamburger menu. I have identified the element and subelement, but I only want to wait for one second without wasting time if the e ...

Accessing the initial item from every list within a specified column of lists

I need help dealing with a pandas dataframe that has columns containing lists of numbers: idx codes new_column 0 [12,18,5] 1 [22,15] 2 [4] 3 [15,1] What is the best way to create a new column in the dataframe that includes only the first el ...

Gather information from a table using pagination features

Attempting to extract data from a paginated table using Selenium. The website being scraped does not have pagination in the URL. table = '//*[@id="result-tables"]/div[2]/div[2]/div/table/tbody' home = driver.find_elements(By.XPATH, &ap ...

How do I ensure that a button can only be clicked when valid values are entered using WebDriver?

I'm currently working on UI automation testing tasks in my job and one thing I am trying to figure out is how to handle a specific scenario. In the application, there is a form where users are required to enter their name and date of birth before the ...

"Looking to update the location of the destination folder on the server using Java Selenium? Learn how to

Check out this Java Code: FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.dir", "C:\\Data"); // folder profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "video/mp4"); ...

Steps to select a radio button according to the provided HTML code

Incorporating the code snippet below as a reference, I am attempting to implement functionality for a radio button. <input id="checkmo" class="radio" type="radio" data-bind="attr: {'id':getCode()}, value: getCode(), checked: isChecked, click: ...

Methods for converting camera calibration parameters stored in a .mat file from Matlab into numpy arrays in Python

After successfully calibrating the camera using Matlab 2019a, I saved all the camera parameters in a variable called cameraParams. However, I am specifically interested in extracting the Intrinsic matrix and distortion coefficients from this data. How c ...

Converting JSON to CSV Using Python

i am currently working with a JSON file structured like this: { "temperature": [ { "ts": 1672753924545, "value": "100" } ], "temperature c1": [ { "ts": 167275392 ...

A Python method for encoding "non-traditional" components of a URL using URL quoting

Below is the URL that I currently have: https://www.verizon.com/OnDemand/TVShows/TVShowDetails/Sr. Avila/1/9 I am looking to encode it in a way that makes it appear like a standard URL, while still remaining valid. For instance: https://www.verizon.com/ ...