简体   繁体   中英

Selenium(Webdriver) in Python doesn't return all links in Google AdWords page

I use webdriver from selenium to download a report from Google AdWords. The problem is that, it seems webdriver doesn't return all links in the page. As it is shown in the attached photo, only links in leftside are returned when I get the pagesource. I need to click on "Run now" link which looks like this in HTML:

<a href="#" onclick="return false;" actionid="runNow" style="white-space:nowrap">Run now</a>

Any comment is appreciated. 使用Python的Google AdWords报告(Selenium和Webdriver)

Here are the codes I have written so far:

baseurl = "https://accounts.google.com/ServiceLogin?service=adwords&continue=https://adwords.google.com/um/identity?ltmpl%3Djfk%26hl%3Den_US&hl=en_US&ltmpl=jfk&passive=0&skipvpage=true"

username = "myUsername"

password = "myPassword"

xpaths = { 'usernameTxtBox' : "//input[@name='Email']",
           'passwordTxtBox' : "//input[@name='Passwd']",
           'submitButton' :   "//input[@name='signIn']"
         }

mydriver = webdriver.Firefox()
mydriver.get(baseurl)
mydriver.maximize_window()

#Clear Username TextBox if already allowed "Remember Me" 
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear()

#Write Username in Username TextBox
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(username)

#Clear Password TextBox if already allowed "Remember Me" 
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear()

#Write Password in password TextBox
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(password)

#Click Login button
mydriver.find_element_by_xpath(xpaths['submitButton']).click()

#Here when I print the source, I do not see any element from the table in the middle of the page
print mydriver.page_source

Finally I could figure out how it can be done, by adding the following code before I open the url:

mydriver.implicitly_wait(60) 

and then:

driver.find_element_by_link_text("Run now").click()

The implicit wait waits to get the elements loaded from DOM. So it is the only solution to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM