I am writing some selenium code to navigate Facebook.
import os
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
def driver():
global driver
driver = webdriver.Chrome("chromedriver.exe", chrome_options=chrome_options)
driver.get("https://facebook.com")
def chrome_options():
global chrome_options
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument('--profile-directory=Default')
# chrome_options.add_argument("--user-data-dir=chrome-data")
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument('disable-infobars')
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
def actions():
global actions
actions = ActionChains(driver)
def login():
try:
# I use environment veriable base on this tutorials https://www.youtube.com/watch?v=IolxqkL7cD8
username = os.environ.get('my_facebook_username')
password = os.environ.get('my_facebook_password')
driver.find_element_by_name("email").send_keys(username)
driver.find_element_by_name("pass").send_keys(password)
driver.find_element_by_name("login").click()
print(input("Press any Key: "))
print("Login work Successfully ")
except:
pass
def navigatePagePostAria():
sleepTime = 4
implicitlyWaitTime = 20
for i in range(2):
driver.implicitly_wait(implicitlyWaitTime)
actions.send_keys(Keys.BACK_SPACE)
actions.send_keys(Keys.TAB * 4)
time.sleep(sleepTime)
actions.perform()
print("Firast 10 tabs Working")
actions.send_keys(Keys.TAB * 3)
actions.send_keys(Keys.ENTER)
actions.perform()
print("Navigate Post area Successfully ")
chrome_options()
driver()
login()
driver.get("https://www.facebook.com/groups/402353916617590/permalink/1630582000461436/")
navigatePagePostAria()
Error Come from last function navigatePagePostAria() The Line will be actions.send_keys(Keys.BACK_SPACE)
error :
Traceback (most recent call last):
File "K:\Project\Python\Miracle\groupPost.py", line 154, in <module>
navigatePagePostAria()
File "K:\Project\Python\Miracle\groupPost.py", line 63, in navigatePagePostAria
actions.send_keys(Keys.BACK_SPACE)
AttributeError: 'function' object has no attribute 'send_keys'
This two line is the most important like for navigation
1.actions.send_keys(Keys.BACK_SPACE)
2.actions.send_keys(Keys.TAB * 4)
I use that as a alternative of x path bechouse facebook is very dynamic its change its x path every minits.
Video Description of my Problem: https://youtu.be/BzSBLAaYS-s
from Keys.BACK_SPACE or Keys.TAB send key is not working on facebook selenium python
No comments:
Post a Comment