1

I'm new with selenium and I'm trying to write a code that will pop-up a item to sell in second hand site. Everything works well until I'm trying to find the pop-up button.

This is how the html code in the site:

snapshot

And this is the line in my code:

pop_up = driver.find_element_by_xpath(("//*[@id='bounceRatingOrderBtn']")).click()

I'v tried to find a solution for hours but nothing worked out for me.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

3 Answers3

0

Is the pop up button appears in a different frame or new window ? Check that and switch to frame or new window as required and then perform perform operation on your button.

I am not familiar with python selenium, I can give java selenium codes for frame and window switch, please understand the logic/code and find python version of code by yourself mate.

Java version of code for Frame switch -

driver.switchTo().frame("yournewframename");

Java version of code for Window switch -

        for(String handle:driver.getWindowHandles()) 
        {
            String windowtitle = driver.switchTo().window(handle).getTitle();
            if(windowtitle.contains("your new pagetitle"))
            {
                System.out.println("Title after switching "+driver.getTitle());
                break;  
            }
        }
Partha
  • 82
  • 8
  • I think that this is the new frame but i can't switch to it with the src and it has no name or id, you got any idea? Thanks! – Lior Moalem Aug 03 '20 at 00:36
  • You can switch to frame using index, try that. driver.switch_to.frame(index number) – Partha Aug 04 '20 at 01:47
0

I Think as Partha siad the problem related to frameworks, I just add python version of switching between frameworks:

driver.switch_to.frame('find your other frame element here') driver.switch_to.default_content()

soswxc
  • 1
  • 1
  • I think that this is the new frame but i can't switch to it with the src and it has no name or id, you got any idea? Thanks! – Lior Moalem Aug 03 '20 at 00:35
0

The desired element is a AJAX element, so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#bounceRatingOrderBtn[name='bounceRatingOrderBtn']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='bounceRatingOrderBtn' and @name='bounceRatingOrderBtn']"))).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
    

References

You can find a couple of relevant discussions on NoSuchElementException in:

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Thank you very much for the answer! when I'm trying this both using xpath and css_selecrot I'm getting an error selenium.common.exceptions.TimeoutException: Message: do you have any idea why? Thanks! – Lior Moalem Aug 03 '20 at 00:27