2

I am trying to create a job that creates a random number generator and if it is above 3, it will hover an element on a website.

Two problems.

EC.element_to_be_clickable((By.css_selector, '.origin-telemetry-shell-submenu-current-area'))).click()

This line does not seem to work. I want to click through all these elements It gives me:

   if ( ww > 3 ):
TypeError: '>' not supported between instances of 'NoneType' and 'int' 

And in relation to the CSS selector line

    Traceback (most recent call last):
      File "C:/Users/Bain3/PycharmProjects/untitled4/ha1.py", line 53, in <module>
        EC.element_to_be_clickable((By.css_selector, '.origin-telemetry-shell-submenu-current-area'))).click()

AttributeError: type object 'By' has no attribute 'css_selector'

The Css selector tends to work in Chrome and in Css Gadget.

I have attached an image and my code in textupload.

http://textuploader.com/d6hqs

https://ibb.co/b3v1U5

Tetora
  • 433
  • 8
  • 25
  • 1
    *if ( ww > 3)* : what does `ww` stands for? – Andersson Aug 30 '17 at 12:53
  • ww should be the random number. If it is above 3, then it goes on to hover the element randomly – Tetora Aug 30 '17 at 12:54
  • 5
    Show how you defined `ww`. It doesn't seem to be number. Also do you mean `EC.element_to_be_clickable(('css_selector', '.origin-telemetry-shell-submenu-current-area'))).click()`? – Andersson Aug 30 '17 at 12:56
  • @Andersson I believe so as .hover() is not correct apparently – Tetora Aug 30 '17 at 13:02
  • definitely :) WebElement has no such attribute as `hover()` . I think you might need [this](https://stackoverflow.com/questions/8252558/is-there-a-way-to-perform-a-mouseover-hover-over-an-element-using-selenium-and) – Andersson Aug 30 '17 at 13:03
  • @Andersson Thanks. I am still getting EC.element_to_be_clickable((By.css_selector, '.origin-telemetry-shell-submenu-current-area'))).click() AttributeError: type object 'By' has no attribute 'css_selector' for line 53. – Tetora Aug 30 '17 at 13:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153253/discussion-between-andersson-and-hayden-darcy). – Andersson Aug 30 '17 at 13:07

3 Answers3

2

You assign to ww the returned value from print(), which doesn't return anything so ww became None. Use ww = randint(0, 9).

By.css_selector should be By.CSS_SELECTOR, all capital.

Guy
  • 46,488
  • 10
  • 44
  • 88
  • Thanks. I am still having trouble with EC.element_to_be_clickable((By.CSS_SELECTOR, '.origin-telemetry-shell-submenu-current-area'))).click() as it seems to ignore the other CSS – Tetora Aug 30 '17 at 13:19
  • @HaydenDarcy What do you mean by *ignore the other CSS*? – Guy Aug 30 '17 at 14:13
1

if (ww > 3) seem to be redundant condition. If you don't want to handle numbers that are less than 3, then just try to replace

# Get list of integers [1, 2, ... n]
indexes = [index for index in range(len(options))]

with

# Get list of integers [3, 4, ... n]
indexes = [index for index in range(3, len(options))]

this should allow you to get list of integers starting from 3

Also, as was already mentioned, By has no such attribute as css_selector.

Note that variable names are case sensitive in Python. So you can use By.CSS_SELECTOR or "css_selector" instead

Andersson
  • 51,635
  • 17
  • 77
  • 129
0

Given this documentation https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html, class By does not contain any css_selector field or property, that is why its raising No Attribute Error, maybe what you are looking for is By.css(your_selector).

Hope it helps.

Agustin
  • 95
  • 2
  • 10