Using a combination of AND and OR in XPATH

Recently, I encountered the following HTML code:

<div><h6>abc/h6><p>date</p></div>

Using Selenium, I managed to locate this element based on text. However, the issue arises when <h6> can contain various words like "def" OR "ghi". How can I incorporate an OR condition in the XPATH query? The current query with only AND works as follows:

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc')]]"

I attempted to add both AND & OR without success:

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc') or preceding-sibling::h6[contains(text(),'def')]]"

Another unsuccessful attempt involved:

"//div/p[contains(text(),'date') and preceding-sibling::h6[contains(text(),'abc' or 'def')]]"

Answer №1

Check the predicate within h6 to see if it includes either 'abc' or 'def':

//div/p[contains(text(),'date') 
  and preceding-sibling::h6[contains(text(),'abc') or contains(text(),'def')]]

Answer №2

Modify the <p> element within the context of and alongside <h3>, ensuring it contains either the text abc or def like so:

//div//p[contains(.,'date')] [//preceding-sibling::h6[contains(.,'abc')] or //preceding-sibling::h6[contains(.,'def')]]

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

Enhancing the efficiency of code in selenium webdriver to locate elements using driver.findElement

I realized that the code I wrote uses the find Element method more than 32 times. I am considering creating a common method for find Element. Do you think it would be beneficial to declare a generic method? ...

Maintaining checked items in their original state while searching for another one in ion-searchbar can be achieved by properly handling

My goal is to maintain the checked items as checked when searching for another item in ion-searchbar. While I have managed to keep the checked items, the checkmark icon does not stay checked. What I aim for is to retain the checked state of all food items ...

Using the Selenium library with the Chrome browser for test automation, along with Maven and JUnit for project

I have a Maven test project that is both keyword driven and data driven using JUnit. After executing the quit keyword, chrome tabs are opening automatically. I am currently using the Chrome browser. I attempted to terminate the process in Eclipse, but th ...

Angular - ngbDropdownMenu items are hidden from view, but their presence is still detectable

Hey there! I'm currently working on a school project and I'm aiming to implement a drop-down menu. Surprisingly, it's proving to be more challenging than expected. <div class="parrent"> <div class="row"> ...

Sliding the slider in Selenium WebDriver: A step-by-step guide

How to move the horizontal progress bar slider For more information, visit: http://jqueryui.com/slider/ I attempted to slide the slider but encountered issues. Below is my Java code: public class SlideSlider { public static void main(String[] args) ...

Discover the seamless method of transferring data from an HTML5 form to a PHP page for processing without the need to refresh the page or manually navigate to the PHP file

When creating a website, I encountered an issue with a form that requires the user to select three options from select elements and then click a search button to search the database. The problem is that PHP does not retrieve the form data unless the button ...

Issues with @font-face and @font-family not being recognized

I've been attempting to achieve a simple task: adding 3 different fonts to an HTML page. After browsing through numerous examples, I still haven't found a solution to my issue. It's possible that I may be missing something in how it's ...

Is there a way to show text as symbols in Primeng components?

Check out this helpful example that demonstrates what I am attempting to achieve. I have implemented p-menu from primeng. Is there a method to convert text into symbols like &trade to ™ and &#8482 to ®? ...

A plug-in for TinyMCE that allows users to adjust column widths within a table

We utilize TinyMCE in our content management system (CMS), and our users have expressed interest in being able to adjust the width of a column within a table. While HTML technically does not recognize columns, the Moodle editor HTMLAREA includes a plugin t ...

Changing textarea html content to an iframe in real time with the use of jQuery

Is it possible to use jQuery to transfer HTML content entered into a textarea to an iframe in real time, without refreshing the page? I have searched for a solution but have not found a clear direction. Any code snippet and explanation would be greatly ap ...

Capture the content of the currently selected cell, launch a web browser, enter the captured content into the search field, and retrieve the URL of the resulting webpage

I want to achieve the following: Retrieve the value of an active cell (a property address) Launch Edge using a Selenium Edge Driver to go to www.redfin.com Search for the value from the cell (the property address) Capture the URL from the search re ...

Unable to locate appropriate Xpath or CSS selector

Is there a way to target this particular element using xpath or css selector? The class name is being used in other parts of the HTML code. Additionally, this div may not always be present in every information block. The desired output within this div sho ...

Using .htaccess to Conceal Directories with Documents

It seems that my website is being targeted by individuals seeking to obtain all the code. I have implemented an .htaccess file that will display nothing when someone visits domain.com/images, but if they specifically request domain.com/images/logo.png, the ...

Outlook not adding padding to button in HTML email

https://i.stack.imgur.com/vMgGS.png Is there a way to apply the same padding to the border as seen on the button above? Adding the border directly to the td element seems like a solution, but it is not feasible due to the presence of border-radius in anot ...

hiding html elements by using the display property set to none instead of physically removing

I am currently utilizing an if-else statement to display different HTML structures. As a result, the entire HTML is being rendered twice. Is there a way we can utilize 'display: none' instead? I attempted to use it in th ...

Tricks for refreshing cached web page assets in the year 2023

So far, here are some of the old Cache Buster techniques I've come across: Adding a query string in the link src: /mstylesheet.css?cache_buster=12345 Changing the filename each time: /mstylesheet-12345.css Using Apache with Cache-Control "must-revali ...

How can the spacing between Angular Material's mat-card-content and mat-card-actions be adjusted?

I am creating a mat card layout where there are two separate cards within the main card's content section. However, when I add a button for the actions section of the main card, there is no spacing between these two sections. How can I create a vertic ...

Calculate the total price using Jquery once selections have been made

I am looking to create a dynamic pricing feature where clicking on a checkbox will update the total price. The prices are calculated per day, so if days are added, the total should reflect that accordingly. Check out our demo here: http://jsfiddle.net/XqU ...

Step-by-step guide to importing a directory in ReactJS

Is there a way to create an input that can upload an entire directory with all its folders intact? I attempted the following code: <input ref={wrapperRef} id="file-upload" name="file-upload" type="file" ...

Executing Selenium tests on a Qt desktop application

I have developed a desktop application using Qt, and now I need to implement automated tests using Selenium. After researching, I came across the QtWebDriver option available on this GitHub repository. Following the instructions on the wiki page (here), ...