0

I've tried several xpaths but non could be used to pass my test. I'm a new comer in the automation world and I'm struggling with this particular problem.

I'm trying to locate the element with text OPTIONS AND FILTERS. If you check this website https://store.steampowered.com/news/ you'll find a side bar and underneath you'll see the OPTIONS AND FILTERS button which I need to click and untick all the options from SHOW THESE TYPES OF POSTS maybe I can do the unticks but before that I need to locate the OPTION AND FILTERS button and click which I'm not being able to. I'm getting

org.openqa.selenium.NoSuchElementException:no such element: Unable to locate element: {"method":"xpath","selector":"(//div[normalize-space()='Your Upcoming Events'])[1]"}
  (Session info: chrome=114.0.5735.199)

Also I've tried explicit waits but no expected result.

I tried many xpaths but couldn't find one which could deliver the right action, as in click the OPTIONS AND FILTERS button.

From the problem I'm facing, I can understand that I need to use Axes xpath but I'm not being able to locate them there are too many elements.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    It's generally a bad idea to tell us that the problem is urgent. We're more likely to help you if we think you're going to take the time to study our response and understand it properly before you rush it into production. It's also inadvisable to ask people to write code for you. We're here to answer your questions, not to do your job. – Michael Kay Jul 06 '23 at 22:30
  • Sorry that I forgot to mention about this that I have been struggling with this for 3 straight days, now I'm out of option this is why I'm seeking help in here, but looks like many of you come up with advises than help, and I never asked someone to do my job in here, but writing xpath for this would make my things clearer. – Robin Hossain Jul 06 '23 at 22:37

2 Answers2

0

You can use chrome developer tools to get the xpath Right click website, inspect element, use the little arrow in the left corner of the developer tools windows to click on the element you want to find out the xpath for.

Now right click the html tag in the dev tools and under copy you have the option to copy the xpath. In this case I was able to get //*[@id="responsive_page_template_content"]/div/div/div/div[1]/div/div[3]/div[6]/div

Hope this helps

0

The element is a dynamic element. So to click on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • Using xpath and normalize-space():

    driver.get("https://store.steampowered.com/news/");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(new By.ByXPath("//div[normalize-space()='Options and Filters']"))).click();
    
  • Using xpath and contains():

    driver.get("https://store.steampowered.com/news/");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(new By.ByXPath("//div[starts-with(@class, 'eventcalendar_FilterSettings')]//div[contains(., 'Options and Filters')]"))).click();
    
  • Browser snapshot:

steampowered


Reference

You can find a detailed discussion on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352