Solution 1 :

Use contains function with and operator, and use .find_element_by_xpath.

Try the following code:

driver.find_element_by_xpath("//span[@class='vRMGwf oJeWuf' and contains(text(), 'Most')]").click()

Solution 2 :

Try taking the webElement reference xpath above the span node.

Then try something like this:

public void selectDataFromList(WebElement we, String data) throws InterruptedException 
{
    Thread.sleep(1000);
    List<WebElement> links = we.findElements(By.tagName("span"));
    for (int i = 0; i < links.size(); i++) {
        System.out.println(links.get(i).getText());
        if (links.get(i).getText().equals(data)) {
            Thread.sleep(1000);
            links.get(i).click();
            Thread.sleep(2000);
            break;
        }
    }
}

Problem :

<span jsslot="" class="vRMGwf oJeWuf">Most relevant</span>
<span jsslot="" class="vRMGwf oJeWuf">Newest</span>
<span jsslot="" class="vRMGwf oJeWuf">Rating</span>

There is a dropdown on this website which has the available values (Most relevant, Newest, Rating). Only “Most relevant” is displayed on the website. How can I get Selenium to click on “Most Relevant” (drop down appears) then click on “Newest”? Please note that “Newest” is not displayed on the website until “Most Relevant” is clicked. The code below could not grab this. Ty for reading.

driver.find_element_by_link_text("Most relevant").click()

By