0

Send keys doesn't work on mac os x, or maybe I'm doing something wrong. maybe I am referencing the keys wrong.

I'm trying to click each link to open in a new tab

Any suggestions?

Main.py

from selenium import webdriver
from selenium.webdriver.common.keys import Keys



driver = webdriver.Chrome()
driver.get('https://orlando.craigslist.org/search/cta')

owl = driver.find_element_by_xpath('//*[@id="sortable-results"]/ul/li/p/a')
res = 1
size = len(driver.find_elements_by_xpath('//*[@id="sortable-results"]/ul/li/p/a'))

def run():
    for i in range(0, size):
        owl = driver.find_elements_by_xpath('//*[@id="sortable-results"]/ul/li/p/a')
        owl[i].click().send_keys(Keys.COMMAND + 't')
        driver.find_element_by_xpath('/html/body/section/header/nav/ul/li[3]/p/a').click()
        if i == 1:
            break


if __name__ == '__main__':
    run()

Here is the error

Traceback (most recent call last):
  File "main.py", line 24, in <module>
    run()
  File "main.py", line 17, in run
    owl[i].click().send_keys(Keys.COMMAND + 't')
AttributeError: 'NoneType' object has no attribute 'send_keys'
SaiPawan
  • 1,189
  • 7
  • 20
BARNOWL
  • 3,326
  • 10
  • 44
  • 80

1 Answers1

0

Based on my experience using Selenium WebDriver on .Net, the .click() does not return an element. It returns nothing. It causes an element to be clicked which in this case would cause a new page to be loaded in the current instance of driver. I think this is what is happening here.

I suggest as an alternative you should collect all of the "href" attributes in all of those < a > elements in an array, then open a new tab for each and switch to the new tab using the answer here how to open a link in new tab (chrome) using selenium webdriver? . Once you've opened a new tab and switched to it, use driver.get() to load the page.

Community
  • 1
  • 1
sevzas
  • 701
  • 2
  • 5
  • 13