RSelenium: What is preventing me from inputting a password into this (Java?) login form?

In the midst of my web scraping endeavors, I have encountered a slight hiccup when trying to extract data from this particular website using RSelenium. While I've had success sending text to various elements on the page, the login field has proven to be quite tricky. It appears that the login form is written in Java, as indicated by the css selectors in SelectorGadget (.j_username & .j_password), which has left me stumped.

If all else fails, I wouldn't mind resorting to manual login, but even that seems elusive at this point =).

remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost",
                                     port = 4445L,
                                     browserName = "chrome")
    remDr$open()

remDr$navigate("https://smd.ch/SMDView/log/index.jsp")
login_name <- remDr$findElement(using = "xpath", "//*[contains(concat( ' ', @class, ' ' ), concat( ' ', 'j_username', ' ' ))]")
login_name$clickElement()
login_name$clearElement()
login_name$clickElement()
login_name$sendKeysToElement(list("xxxxxxx"))
login_pw <- remDr$findElement(using = "xpath", "//*[contains(concat( ' ', @class, ' ' ), concat( ' ', 'j_password', ' ' ))]")
login_pw$click()
login_pw$clearElement()
login_name$click()
login_pw$sendKeysToElement(list("xxxxxxx", "\uE007"))
remDr$screenshot(display = TRUE)

Answer №1

It appears there is an issue with the xpath method. You can try using the following xpaths to locate the elements for username and password.

//div[@class='login_screen']//input[@name='j_username']

//div[@class='login_screen']//input[@name='j_password']

Answer №2

In the webpage, there are multiple login options available - one for mobile and one for desktop. Depending on the screen size or user agent being simulated, only one of these logins is visible while the other remains hidden. To access the desktop login, use the following xpath expressions:

//*/div[@class='login_screen']//*[contains(@class,'j_username')
//*/div[@class='login_screen']//*[contains(@class,'j_password')

For testing xPath expressions, a general tip would be to open the webpage in Google Chrome, access the developer tools, and navigate to the Console tab. Then input: $x("XPATH"), replacing XPATH with your desired expression to test. Press enter and Chrome will display the results for the active page, allowing you to click on them for highlighting - even if they are invisible. This method of testing xPath expressions in Chrome before implementation in code can save you a significant amount of time.

Answer №3

It appears that you were quite close in your approach. It seems that the Locator Strategies you used identified multiple elements, causing functions like clearElement(), clickElement(), and sendKeysToElement() to interact with the first matching element found within:

<div class="login_mobile">

rather than the desired element:

<div class="login_screen">

Solution

In order to interact with the login fields, you can use the following Locator Strategies:

  • cssSelector

    • The Benutzername field:

      div.login_screen input.inputfield.j_username[name='j_username']
      
    • The Passwort field:

      div.login_screen input.inputfield.j_password[name='j_password']
      
  • xpath :

    • The Benutzername field:

      //div[@class='login_screen']//input[@class='inputfield j_username' and @name='j_username']
      
    • The Passwort field:

      //div[@class='login_screen']//input[@class='inputfield j_password' and @name='j_password']
      

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

How can I send data in JSON format to a JavaScript AJAX request?

I've created a method that looks like this: public String getUTResult() throws IOException { BuildResultParser bp = new BuildResultParser(); BuildResultBean b = bp.getreadFile("C:\\bc.txt"); String str = b.getuTresult(); ...

Error: The session ID is not currently active

I encountered a problem with my tests failing when running them on TFS, showing the following error: WebDriverError: No active session with ID Failed: No active session with ID Interestingly, these same tests are passing locally. Everything was working ...

The AJAX response consistently returns a 405 status code

I am experiencing an issue with an AJAX post request. $.ajax({ type: "POST", contentType: "application/json", url: "/rating/save", data: JSON.stringify(rating), dataType: "json", mimeType: "application/json" ...

Analyzing Dynamic Content

Currently, I am engaged in content parsing and have successfully executed a sample program. To demonstrate, I have utilized a mock link which you can access below: Alternatively, you can click on this link: Click Here In the provided link, I have parsed ...

Selenium unable to interact with Javascript pop-up box

I am currently working on automating a feature for our web application, specifically a form of @mentioning similar to Facebook. On the front end, when a user types @ into a text input, the API is called to retrieve the list of users and display them in a b ...

Can you tell me the distinction between using RemoteWebDriver's executeScript() and Selenium's getEval() for executing

Can you explain the distinction between these two pieces of code: RemoteWebDriver driver = new FirefoxDriver(); Object result = driver.executeScript("somefunction();"); and this: RemoteWebDriver driver = new FirefoxDriver(); Selenium seleniumDriver = ne ...

Generating a tree structure using a JavaScript array

Looking to build a tree structure from a given list of data where the paths are represented like: A-->B-->C-->D-->E.. A-->B-->C-->D-->F.. A-->F-->C-->D-->E.. . . . All possible data paths are stored in an array. The de ...

Is there a way to find the JavaScript Window ID for my current window in order to utilize it with the select_window() function in

I'm currently attempting to choose a recently opened window while utilizing Selenium, and the select_window() method necessitates its WindowID. Although I have explored using the window's title as recommended by other sources, and enabled Seleni ...

How can we use the Selenium JavascriptExecutor in Java to return an Object from JavaScript?

I've encountered an issue while running a JavaScript file using Java with Selenium in my application. When I execute the JavaScript file with JavascriptExecutor after logging in, I'm only getting a null return instead of a valid one. Below is a ...

Is there a way to access an Excel file with JavaScript without relying on the ActiveX control?

Is there a way to access an Excel document using JavaScript code without relying on an ActiveX control object such as shown below: var myApp = new ActiveXObject("Excel.Application"); myApp.workbooks.open("test.xls"); ...

Unable to retrieve the text enclosed between the:: before and after the:: marker

I attempted this using the XPATH finder in Chrome, and it highlighted the element. However, when running my Selenium script, I received the following error: Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: ...

Testing a cucumber scenario by comparing the redirect URL with a different URL

Currently, I am working on writing Cucumber tests for my project. One issue I have encountered is that when clicking a certain button in my code, it redirects to another page with a fixed URL. How can I retrieve the current URL within the Cucumber test? I ...

Sending data from an AJAX request to a Spring controller is a common task in web

var TableDatatablesEditable = function () { var handleTable = function () { function restoreRow(oTable, nRow) { var aData = oTable.fnGetData(nRow); var jqTds = $('>td', nRow); for (var i = 0, ...

Mastering the use of getText() in Protractor with Page Object Model in Javascript

Having trouble retrieving specific values from my page object. The getText() method is returning the entire object instead of just the text, likely due to it being a Promise. I can provide my code if necessary, but I'm aiming to achieve something sim ...

Is there a dependable resource for mastering Protractor along with the Jasmine Framework in Eclipse using JavaScript?

Starting a new role at my organization where I will be testing Angular JS applications. Can anyone recommend a good website for learning PROTRACTOR with JAVASCRIPT using the JASMINE Framework? (Would prefer if it includes guidance on Eclipse IDE) Thank yo ...

Having trouble choosing an option from the dropdown menu with Puppeteer Js

I need help with Puppeteer JS to select the initial element in a dropdown. Any suggestions? Once I input the city name in the text field, I want to choose the first option from the dropdown menu. const puppeteer = require('puppeteer'); (async ...

Executing a JavaScript code in a Python webdriver: A step-by-step guide

Using Selenium 2 Python webdriver: I encountered an issue where I needed to click on a hidden element due to a hover effect. In search of solutions to unhide and select the element, I came across the following examples: Example in Java: JavascriptExecut ...

Is it possible to stop an AjaxBehaviorEvent listener or send extra information to the f:ajax onevent function?

In the controller, I have created a listener that looks something like this: public class FooController { public void doSomething(AjaxBehaviorEvent evt) { closeDialogFlag = true; .. if(!isValid){ closeDialogFlag = f ...

Initiate the process of displaying data on a datetime chart using Highcharts

I am currently developing a yearly chart, but I've encountered a small issue. The chart begins in January, however there is no data available until May. The client specifically wants the chart to only display when there is data available, and unfortu ...

Selenium Assistance: I'm encountering a scenario where on a webpage, two elements share the same Xpath, making it difficult to differentiate them based on even

At index [1], both elements are identified, but at index [2], nothing is identified. The key difference between the two is that one has display:none, and the other has display:block. However, their involvement in determining these fields is minimal due to ...