2

So, there is a site that gets generated by javascript. And updates every second. And I want to get the values every second. But the site will pop up a modal asking "Are you still here". And then you need to click the button. So first my code looks like this:

    try:
        button = browser.find_elements_by_xpath("//button[contains(@value, 'Refresh Page')]");
        button.click()
        rounds = rounds+1
    except:
        rounds = rounds+1

But when I look at my browser, it still reloads every round, even tho it doesn't show up in screen.

How can I make this work, to only click the button when it's on screen? Thanks!

11
  • 1
    can you change find_elements_by_xpath to find_element_by_xpath and try Commented Mar 13, 2019 at 11:06
  • Nope, it still reloads it every time @NarendraR Commented Mar 13, 2019 at 11:08
  • can you share the site URL ? Commented Mar 13, 2019 at 11:08
  • 2
    @NarendraR I think it's a typo, else OP would have got AttributeError: 'list' object has no attribute 'click' Commented Mar 13, 2019 at 11:09
  • @NarendraR The url is rolimons.com/deals Commented Mar 13, 2019 at 11:11

1 Answer 1

1

Go through the below code to click on the button once it available and visible to refresh the page

button = browser.find_elements_by_xpath("//button[contains(@value, 'Refresh Page')]");

//To check button is present on page

if (len(button)>0):  

//And is displayed

if button[0].is_displayed():
      button[0].click()
   else:
      print "button not display"
else: 
    print("there is not refresh page button") 

OR

// to check the dialog present here "show" is the class which retain by the div once the refresh button get enabled

if "show" in browser.find_element_by_id('timeout_dialog').get_attribute('class'):
   browser.find_element_by_xpath("//button[contains(@value, 'Refresh Page')]").click()
else:
  print "refresh button not displaying"

Note : make the syntax correction as per python

Sign up to request clarification or add additional context in comments.

5 Comments

Your indent is incorrect in the second half of your first block of code. The second if (and following) should be indented because it should be inside the first if. Also, python comments are # not //, see the docs
@JeffC, Yep I'm aware of that's why i have added a note as there is restriction to post the plain code in my system.
I don't understand why you can't fix it??? You need to fix it or it's not correct, especially the first part.
That's kinda rude, yes? I can fix it but it's not my job to go around and fix everyone else's mistakes. I pointed them out to you... why can't you fix them? Do you usually have others come and clean up your messes? Your answer is wrong as posted, I pointed out the mistakes and you have refused to fix them.
You already posted the code, all you have to do is indent it properly. If you can't do that for some reason at work, then fix it when you get home. Either way, I explained why and where the answer is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.