I need to edit this file with any python module:
https://1drv.ms/x/s!Aq2lKlhSyqf5mjiC6CYkC1QGXNSy?e=Wh88AT
but I don't want to download it edit and then upload again. I tried using webbot, but I couldn't even find the 'editing mode' button.
import time
from time import sleep
from webbot import Browser
driver = Browser()
driver.new_tab(url='https://1drv.ms/x/s!Aq2lKlhSyqf5mjiC6CYkC1QGXNSy?e=Wh88AT')
driver.switch_to_tab(1)
driver.close_current_tab()
print("waiting...")
sleep(20)
print("start")
driver.click(classname = 'list-349' , tag = 'button' )
but it returns this:
Traceback (most recent call last):
File "main.py", line 19, in <module>
driver.click(classname = 'list-349' , tag = 'button' )
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/webbot/webbot.py", line 466, in click
maxElements = self.__find_element(text, tag, classname, id, number, css_selector, xpath, loose_match)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/webbot/webbot.py", line 294, in __find_element
element_fetch_helper(("//body//{}".format(tag)), score=50)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/webbot/webbot.py", line 202, in element_fetch_helper
add_to_init_text_matches_score(self.driver.find_elements_by_xpath(xpath), score)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 410, in find_elements_by_xpath
return self.find_elements(by=By.XPATH, value=xpath)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 1005, in find_elements
return self.execute(Command.FIND_ELEMENTS, {
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=91.0.4472.101)
(Driver info: chromedriver=2.39.562737 (dba483cee6a5f15e2e2d73df16968ab10b38a2bf),platform=Linux 5.15.0-1012-gcp x86_64)
I'm using replit by the way.
Related
Here is the code which I use to open the new tab using Selenium Python,
self.driver.execute_script("window.open(arguments[0])", self.listing_url)
self.driver.switch_to.window(self.driver.window_handles[1])
time.sleep(10)
and it works perfectly. But I am planning to use WebDriverWait instead of time.sleep
self.driver.execute_script("window.open(arguments[0])", self.listing_url)
self.driver.switch_to.window(self.driver.window_handles[1])
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//div[#class="honbun"]')))
and when I am using it, it's throwing an error. Here is the error log:
Traceback (most recent call last):
File "D:\tender_scraper\engine\Spider.py", line 308, in parse_index_page
index_handle = self.load_listing_page(listing, i, index_listing)
File "D:\tender_scraper\spiders\gunmapref_listing_spider.py", line 298, in load_listing_page
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//div[#class="honbun"]')))
File "D:\scraper\lib\site-packages\selenium\webdriver\support\wait.py", line 78, in until
value = method(self._driver)
File "D:\scraper\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 64, in _predicate
return driver.find_element(*locator)
File "D:\scraper\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1251, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "D:\scraper\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "D:\scraper\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: missing or invalid columnNumber
(Session info: headless chrome=104.0.5112.48)
Any idea what's wrong with it & how to solve it? Previously, I used chrome 103 and changed it to 104 but still got the same error. It seems the error only occurs when changing into the new tab.
I know this question was already answered here but I wouldn't be typing this if it worked for me.
I'm making a bot that gets a random image from Bing and returns it's URL to later send it to Discord. Here's my code so far:
import random
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
from time import sleep
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument('headless')
edge_options.add_argument('disable-gpu')
driver = Edge(executable_path='PATH/TO/DRIVER', options=edge_options)
def Image(query):
query.strip()
query.replace(' ', '+')
ImageUrl=f'http://www.bing.com/images/search?q={query}'
driver.get(ImageUrl)
#Wait for page to fully load
sleep(5)
all_images = driver.find_elements_by_class_name('mimg')
random.choice(all_images).click()
sleep(5)
parent = driver.find_element_by_class_name('nofocus')
source = parent.get_attribute('src')
return source
print(Image('cat'))
driver.quit()
When runing the above code I get this:
Traceback (most recent call last):
File "PATH/TO/FILE", line 52, in <module>
print(Image('cat'))
File "PATH/TO/FILE", line 27, in Image
parent = driver.find_element_by_class_name('nofocus')
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 413, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 750, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"class name","selector":"nofocus"}
(Session info: headless MicrosoftEdge=87.0.664.57)
(Driver info: msedgedriver=87.0.664.55 (097391c0e48fdc4ded0e5c4367f7055dc71815ed),platform=Windows NT 10.0.19042 x86_64)
Exception ignored in: <function Service.__del__ at 0x0000021FD11A2820>
Traceback (most recent call last):
File "PATH/TO.FO", line 163, in __del__
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 139, in stop
File "C:\Users\axeld\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 110, in send_remote_shutdown_command
ImportError: sys.meta_path is None, Python is likely shutting down
What is happening?
I followed this tutorial for Selenium with Python:
So I did the same as the tutorial:
from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://www.youtube.com/')
searchbox = driver.find_element_by_xpath('//*[#id="search-input"]')
searchbox.send_keys('cooking')
But I get this error:
Traceback (most recent call last):
File "C:/ANGUS/DATA_ANALYSIS/WEBSCRAPING/TextXXX.py", line 7, in <module>
searchbox.send_keys('cooking')
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=81.0.4044.138)
How can I fix this?
Another way to do that in order not to use the search is by inserting the query itself.
Code:
your_query = "cooking"
driver.get("https://www.youtube.com/results?search_query=" + str(your_query))
time.sleep(5)
In this way, it is like you are going immediately in the output that you want after searching a specific query of yours. So, let's say that instead of typing cooking, you can .get() to the URL you want by adding your query into this URL.
I'm trying to get this conditional working but I'm getting traceback.
I want to look if the element is present on the website and if it is refresh and execute redeem_func() and if the element is not present at all
I want to not execute err_reddem_func() and move on to this
By the way, I don't know if it's relevant but if there was no error on the webpage it redirects to the last step website and saves URL to txt.
Exception in thread Thread-6:
Traceback (most recent call last):
File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:/Users/lulu/Desktop/s/s/threaddo.py", line 352, in execute_chrome
s(elem[0], elem[1], elem[2])
File "c:/Users/lulu/Desktop/s/s/threaddo.py", line 323, in s
err_redeem_func()
File "c:/Users/lulu/Desktop/s/s/threaddo.py", line 314, in err_redeem_func
err_redeem = driver.find_element_by_class_name('error')
File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 564, in find_element_by_class_name return self.find_element(by=By.CLASS_NAME, value=name)
File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value'] File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\lulu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"class name","selector":"error"} (Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Windows NT 10.0.17763 x86_64)
My Code
def redeem_func():
capHome = cap_home()
print("redeem_func")
driver.execute_script("redemptionValidation(\"" + capHome + "\")")
time.sleep(10)
redeem_func()
time.sleep(1)
print(driver.current_url)
def err_redeem_func():
err_redeem = driver.find_element_by_class_name('error')
try:
if err_redeem.is_displayed() and err_redeem.is_enabled():
driver.refresh()
redeem_func()
except NoSuchElementException:
pass
err_redeem_func()
print(driver.current_url)
print("SAVING TO TXT")
finalCode = driver.current_url
f = open('t.txt','a')
f.write('\n' + finalCode)
f.close()
Replace the below line
if err_redeem.is_displayed() and err_redeem.is_enabled():
with
if (len(driver.find_elements_by_class_name('error'))>0):
You are getting NoSuchElement exception because the script is trying to check if the element is enabled when the element is not there on the page.
I am automating a mac desktop application using selenium and AppiumForMac using language Python. I want to locate a set of elements which has same xpath. For this, I have used "find_elements_by_xpath()". But when running the script, I got the following error:
File "xxxxx_automation.py", line 740, in <module>
createNewTemplate()
File "xxxxx_automation.py", line 102, in createNewTemplate
roles_supported = driver.find_elements_by_xpath("/AXApplication[#AXTitle='XXXXX']/AXWindow[#AXIdentifier='_NS:10' and #AXSubrole='AXStandardWindow']/AXSheet[0]/AXScrollArea[#AXIdentifier='_NS:220']/AXTable[#AXIdentifier='_NS:224']/AXRow[#AXSubrole='AXTableRow']/AXCell[0]/AXButton[#AXIdentifier='RoleCheckBoxButton']")
File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 366, in find_elements_by_xpath
return self.find_elements(by=By.XPATH, value=xpath)
File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 858, in find_elements
'value': value})['value']
File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
Code snippet that causes error:
roles_supported = driver.find_elements_by_xpath("/AXApplication[#AXTitle='XXXXX']/AXWindow[#AXIdentifier='_NS:10' and #AXSubrole='AXStandardWindow']/AXSheet[0]/AXScrollArea[#AXIdentifier='_NS:220']/AXTable[#AXIdentifier='_NS:224']/AXRow[#AXSubrole='AXTableRow']/AXCell[0]/AXButton[#AXIdentifier='RoleCheckBoxButton']")
for roleSupported in roles_supported:
print "TEST"
role_name=roleSupported.text
print role_name
if role_name == "RtpToMp4-QS":
clickElement(roleSupported)
break
time.sleep(2)
Can anybody help in this?