Questions tagged [relative-locators]

Relative Locators provides the opportunity to find elements based on their relative location on the page from a root elelemt.

Selenium 4 reintroduced Relative Locators which was previously known as Friendly Locators. The core concept behind this method is to allow users to find elements based on how one would describe them on a page incase it is easier to describe spatially where the element is in relation to an element that does have an constructed locator.

The available locators are:

  • above
  • below
  • toLeftOf
  • toRightOf
  • near
29 questions
2
votes
1 answer

Finding the Xpath of the Download Link, it is showing as li, Need help in this. I have used the Contains as well but not working

I am trying to find the Xpath for the below image. The one on the right is the Download File link and the right is element DOM. enter image description here I have tried with directly copying the Xpath and also used the Contains text "Download File"…
2
votes
1 answer

How to find elements based on computed style

I wanted to find all element having specific font color in my selenium automation project. but as the font color style is not inline it will not be visible in DOM. Is there anyway to find elements based on their computed style? may be using xpath or…
2
votes
3 answers

How to write cypress locator for this dynamic button specific to the span element "Agile Fundamentals"

I am new to cypress automation. I tried to use the following locator to click on the specific dynamic button. cy.contains('span', 'Agile Fundamentals').next().find('button').click() but it did not work.
Rock
  • 115
  • 7
2
votes
2 answers

How to find the neighbour element of an active element using Selenium with Python or Perl

This is a inverse question of $driver.get_element_by_xpath(....) Background I have a series of dynamically generated pages to parse. The target element doesn't have a good locator, xpath, text, or id. However, the neighbor element has a unique…
oldpride
  • 761
  • 7
  • 15
1
vote
0 answers

Selenium - Datepicker - Dropdown - Unable to locate

I have a datepicker table on a web page. It has 2 dropdowns for 'Month' and 'Year', like below: I am able to locate the dropdown boxes. However, the peculiar issue is that, when I am trying to select any of those dropdowns or select any element…
1
vote
1 answer

How to perform click action on this particular button?

I was asked this question on interview. I need to perform click action on "open" button which is opposite to "CLR-9194": I told that with help of index I can perform action on that particular "open" button: findElement(By.xpath("//label[2]")) But…
1
vote
1 answer

TypeError: Object of type RelativeBy is not JSON serializable error using relative_locator through Selenium Python

I'm trying to write my own flight tracker using selenium and chrome driver. In order to get to the input box, I'm trying to travel down the tree of embedded html elements (for some reason I can't get straight to it, even using the xpath attribute in…
1
vote
1 answer

Selenium 4 Relative Locator - How to locate the First Name input box using Selenium with Java

I am unable to enter the text in the input box which is to the right of the label "FirstName" using selenium 4 toRightOf. WebDriverManager.chromedriver().setup(); WebDriver driver = new…
Bimlesh
  • 269
  • 2
  • 9
  • 20
1
vote
1 answer

How to to write cypress locator for dynamic input field

How to write locator for this highlighted input field element when ID and Class attribute are dynamic? Also for this button
Rock
  • 115
  • 7
1
vote
2 answers

locate html element that change position with selenium Python

List: So i have this list and need a way to find any of the users, the problem is that the position of users changes and with xpath is imposible because the div position takes the users thats in that div, not the user that a want to…
1
vote
1 answer

How to get the count of likes from a Twitter post using Selenium?

I'm trying to find a way to get the likes counter from any given Twitter post. For example, this tweet: https://twitter.com/whale_alert/status/1508925640745140232 I have tried using every element around that text with no success. What should I call…
1
vote
2 answers

TypeError: Object of type RelativeBy is not JSON serializable error using Selenium 4's Relative Locator with Python 3

I am running Python 3.7.1 and Selenium 4.0.0a6. I want to use the new Relative Locator functions in Selenium 4 but always get a: TypeError: Object of type RelativeBy is not JSON serializable error. More specifically, I first call: the_name =…
0
votes
0 answers

Javascript exception in Selenium - Java - org.openqa.selenium.JavascriptException: [object Object]

The line in the code is: a = driver.findElement(RelativeLocator.with(By.tagName("style")).toRightOf(By.tagName("colspan"))).getText(); There is a very long essay by way of error in the Console section, including am MIT license disclaimer (?)... I…
0
votes
0 answers

Partial text gets retrieved from getTextFromXpath function where we are passing a xpath to the function

I have created a function as written below, under the action utility under the framework: public String getTextByXpath(WebElement xpath) throws Exception { waitForXPath("wait for element", xpath); Assert.assertNotNull(xpath); …
0
votes
0 answers

Trouble locating element using selenium webdriver

I am trying to locate a date picker on the UI. The datepicker is only displayed when the override checkbox is clicked and I am able to locate that but not able to locate the month and year Drop downs. They do not contain ID or unique names and the…
1
2