1

I am trying to click on the "most helpful first" dropdown list and change it into the newest reviews for android playstore apps.

https://play.google.com/store/apps/details?id=com.nintendo.zama&showAllReviews=true

tried multiple methods such as the below method also by finding the class and by xpath but nothing worked.

new_comments = driver.find_element_by_link_text('"Most helpful first"').click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

5 Answers5

1

You should use the find_element_by_link_text method for the link text.

For instance, consider this page source:

<html>
<body>
  <p>Are you sure you want to do this?</p>
  <a href="continue.html">Continue</a>
  <a href="cancel.html">Cancel</a>
</body>
<html>

So if you want to click by link text:

continue_link = driver.find_element_by_link_text('Continue')
continue_link = driver.find_element_by_partial_link_text('Conti')

BUT, In your case, the 'Most helpful first' text is not a link text it is in the <span> tag.

So you can use the driver.find_element_by_css_selector method or the driver.find_element_by_xpath method:

CSS:

driver.find_element_by_css_selector('.KKjvXb > span');

XPATH:

driver.find_element_by_xpath("//span[text() = 'Most helpful first']");
Yevhen Laichenkov
  • 7,746
  • 2
  • 27
  • 33
1

To click() on the element with text as Most helpful first and then to click() on the element with text as Newest you need to induce WebDriverWait for the desired element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    driver.get('https://play.google.com/store/apps/details?id=com.nintendo.zama&showAllReviews=true')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Reviews']//following::span[text()='Most helpful first'][1]"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Reviews']//following::span[text()='Most helpful first'][1]//following::span[text()='Newest']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

Browser Snapshot:

play_google_com

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

it's not this element, you should use other element and use send_keys, to check it you need press F12 and watch for element that highlights "Most helpfull first" field. it's parrent of that element that you already looking for, for me is something like this:

from selenium.webdriver.common.keys import Keys
driver.find_element_by_xpath('//*[@class="MocG8c UFSXYb LMgvRb KKjvXb"]').send_keys(Keys.ARROW_DOWN, Keys.ARROW_DOWN)

then you saw another list and you need to find good element from list:

driver.find_elements_by_xpath('//div[@jsname="wQNmvb"]')[-3].click()

I use index -3 because there is 6 elements with that same xpath.

Krzy
  • 83
  • 7
0

Try it in browser console and execute this using javascript executor::

$x("(//span[text()='Most helpful first'])[1]")[0].click();

Tanuj Vishnoi
  • 309
  • 2
  • 8
-1

I managed to do it this way.

dropdown = driver.find_element_by_xpath('//*[@id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/c-wiz/div[1]/div/div[1]/div[2]').click()
sleep(2)
new_comments = driver.find_element_by_xpath('//*[@id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/c-wiz/div[1]/div/div[2]/div[1]').click()