this buttons are not getting clicked
agree_button = driver.find_element_by_xpath('//*[#id="rightsDeclaration"]')
submit = driver.find_element_by_xpath('//*[#id="submit-work"]')
def upload():
agree_button.click()
time.sleep(1)
submit.click()
upload():
however i noticed that when the function is called, the url gets selected like this:
Url selected when the function is called
i tried locating with the id, the name , the xpath , everything and nothing
the buttons:
and also i notcied that the page scrolls a bit down (and not clicking ofc) and that's it. what's the problem?
full code:
copy_settings_link = "https://www.redbubble.com/portfolio/images/68171273-only-my-dog-understands-me-beagle-dog-owner-gift/duplicate"
def copy_settings():
driver.get(copy_settings_link)
replace_image_button = driver.find_element_by_xpath('//*[#id="select-image-base"]')
time.sleep(1)
replace_image_button.send_keys(Path_list[0])
upload_check = driver.find_element_by_xpath(
'//*[#id="add-new-work"]/div/div[1]/div[1]/div[1]/div') # CHECKING UPLOAD
while True:
if upload_check.is_displayed() == True:
print('Uploading...')
time.sleep(1)
else:
print('Uploading Finished')
time.sleep(1)
break
copy_settings()
def upload():
agree_button.click()
time.sleep(1)
submit.click()
upload()
Problem Fixed Guys:
this
chrome_options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data") # Stay LOGGED IN
can anyone explain please to me how this code works? it let me stay logged in in the site
Related
When I try to scroll until the presence of particular text by using a scroll utility its toasting InvalidSelectorException. I need to scroll to a text in mobile screen I am using pytest Appium framework
class ScrollUtil:
#staticmethod
def scroll_to_text_by_android_uiautomator(text, driver):
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,(
"new UiScrollable(new UiSelector().scrollable(true).instance(" "0)).scrollIntoView(new UiSelector().textContains(\"" + text + "\").instance(0)")).click()
def follow_and_unfollow_button_working_people_you_may_know(self):
ScrollUtil.scroll_to_text_by_android_uiautomator("People you may know",self.driver)
self.click("follow_button_text")
follow_working = self.display_result("unfollow_button_text")
while follow_working == True:
print("Working of follow button is verified in People you may know")
break
self.click("unfollow_button_text")
unfollow_working = self.display_result("follow_button_text")
while unfollow_working == True:
print("Working of unfollow button is working in People you may know")
break
Here the code which i am trying
I'm trying to use SendMouseWheelEvent to pass mouse scrolls into the browser, but it is only working on the first page load. Any subsequent pageloads after that, it does not work, unless the browser is interferred with actual mouse scroll.
I've prepared the following script. The "errorrep" is actually the name of the script itself, as "errorrep.py", into which I'm assigning the browser as "mybrowser".
How can I have the browser correctly work with SendMouseWheelEvent on subsequent pageloads?
cefpython version is 66.1.
"""
SendMouseWheelEvent is correctly performed on the first page load. On any pageloads after that, it does not seem to work, but it works again when the actual mouse device performs a scroll on the webpage
'# test 1' which does a javascript code 'scrollBy', works on every pageload.
'# test 2' which does a SendMouseWheelEvent, only works on first page load.
"""
from cefpython3 import cefpython as cef
import time
from threading import Thread
import errorrep
mybrowser = None
def main():
cef.Initialize()
browser = cef.CreateBrowserSync(url="https://stackoverflow.com/")
browser.SetClientHandler(LoadHandler())
errorrep.mybrowser = browser
cef.MessageLoop()
del browser
cef.Shutdown()
class LoadHandler(object):
def OnLoadingStateChange(self, browser, is_loading, **_):
if not is_loading:
Thread(target=test).start()
def test():
print("Page loading is complete!")
for i in range(5):
print('scrolling')
# test 1
errorrep.mybrowser.ExecuteJavascript(jsCode="""scrollBy(0,25)""")
# test 2
# errorrep.mybrowser.SendMouseWheelEvent(0,0,0,-120, cef.EVENTFLAG_NONE)
time.sleep(1)
print('opening new page, clicking on the logo link')
errorrep.mybrowser.ExecuteJavascript(jsCode="""document.getElementsByClassName('s-topbar--logo js-gps-track')[0].click();""")
if __name__ == '__main__':
main()
Does anyone know how I can add this in my code? This is the code:
def cookieclicker(num):
cookie = driver.find_element_by_id("bigCookie")
for i in range(num):
cookie.click()
def store_upgrades():
products = driver.find_elements_by_class_name("upgrade")
for upgrade in products:
upgrade.click()
def upgrades():
items = driver.find_elements_by_class_name("enabled")
for item in items[::-1]:
item.click()
#main loop
def main():
while True:
cookieclicker(80)
try:
upgrades()
except:
continue
try:
store()
except:
continue
if keyboard.is_pressed("q"):
break
main()
As you can see the code consists of 4 function which click the cookie and buys all the upgrades. It would be great if anyone could help with the last step, the golden cookie!
I run game and observed HTML and it seems it shows golden cookie in
<div id="shimmers">
and it adds
<div class="shimmer" alt="Golden cookie" ...>
so you could search it using class shimmer
try:
find_element_by_class_name('shimmer').click()
except:
pass
or using xpath //div[#alt="Golden cookie"] if you selected English language.
In other languages it uses native name - i.e in Polish it uses alt="Złote ciastko".
try:
find_element_by_xpath('//div[#alt="Golden cookie"]').click()
except:
pass
But I didn't test if it work.
HTML in DevTool:
Full browser:
I wrote this script with Python tkinter and Selenium.
I create a button, when we click on it, 2 functions have to be executed. But I don't know why, it doesn't work well, only the first one: login() is executed and the second one: kalk() will not be executed.
If I put all the lines of the 2 functions in only one function, it works until the end without any problem.
Why does the below code not work ?
Here is the code (only a part of the program):
def login():
boutoncount.config(state='disabled')
browser = webdriver.Chrome(executable_path=r"C:\Users\Bat02\Desktop\Python\Selenium Test\chromedriver.exe")
browser.get('url')
time.sleep(10)
login= browser.find_element_by_id("UserID")
pwd = browser.find_element_by_id("Password")
confirm= browser.find_element_by_id("LogIn")
login.send_keys(loginentry.get())
pwd.send_keys(pwdentry.get())
time.sleep(3)
confirm.click()
def kalk():
time.sleep(10)
kalknum= browser.find_element_by_id("txt_Kalk")
eigkalkuncheck=browser.find_element_by_id("chk_Kalk")
eigkalkuncheck.click()
kalknum.send_keys(user_entries[0].get())
boutoncount=Button(fenetre,text="count",width=800,height=1,bg="white", font="bold",bd=5, command=lambda:[login(),kalk()])
boutoncount.pack(side=BOTTOM)
Thank you !
I am dealing with a pop up issue that seems to be random before I click on a button. I want to know if there is any way I can check if the element is displayed and click it, if it is not displayed, i want it to continue running the script. my current script keeps getting an error. when the pop up is displayed, my script runs PERFECT. my error takes place on my script at the
onetouch = self.driver.find_element _by_xpath("").
Here is a picture of my error:
self.driver.get(redirecturl)
self.driver.implicitly_wait(180)
login_frame = self.driver.find_element_by_name('injectedUl')
# switch to frame to access inputs
self.driver.switch_to.frame(login_frame)
# we now have access to the inputs
email = self.driver.find_element_by_id('email')
password = self.driver.find_element_by_id('password')
button = self.driver.find_element_by_id('btnLogin')
# input your email and password below
email.send_keys('')
password.send_keys('')
button.click()
#############
onetouch = self.driver.find_element_by_xpath(".//*[#id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a")
if onetouch.is_displayed():
time.sleep(2)
onetouch.click()
else:
print "onetouch not present....continuing script"
button2 = self.driver.find_element_by_id('confirmButtonTop')
button2.click()
button3 = self.driver.find_element_by_name('dwfrm_payment_paypal')
# if you want to test the program without placing an order, delete the button3.click() below this.........
button3.click
Actually find_element_by_xpath always returns either element or throws exception, So if there is no element by provided locator you can't execute is_displayed(). You should try using find_elements_by_xpath instead and check the length as below :-
onetouch = self.driver.find_elements_by_xpath(".//*[#id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a")
if len(onetouch) > 0:
time.sleep(2)
onetouch[0].click()
else:
print "onetouch not present....continuing script"
-------
Try following:
from selenium.common.exceptions import NoSuchElementException
try:
time.sleep(2)
self.driver.find_element_by_xpath(".//*[#id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a").click()
except NoSuchElementException:
print "onetouch not present....continuing script"