selenium

Clicking multiple items on one page using selenium

Deadly 提交于 2021-02-11 12:26:26
问题 My main purpose is to go to this specific website, to click each of the products, have enough time to scrape the data from the clicked product, then go back to click another product from the page until all the products are clicked through and scraped (The scraping code I have not included). My code opens up chrome to redirect to my desired website, generates a list of links to click by class_name. This is the part I am stuck on, I would believe I need a for-loop to iterate through the list of

Unable to get an element via query on attribute(containing hyphens) value using an XPATH

旧巷老猫 提交于 2021-02-11 12:23:06
问题 I'm facing a very weird scenario in getting an element having an attribute using an XPATH. The problem is that if the attribute contains more than one Hyphens in it then Selenium is unable to find that element. I am using Python and Selenium 2.52.0 Example that works fine. <span data-one="containingOnlyOneHyphen"> </span> XPATH = '//*[@data-one="containingOnlyOneHyphen"]' (Works Completely Fine) Example that doesn't work. <span data-one-two="containingTwoHyphen"> </span> XPATH = '//*[@data

How do I make Internet Explorer driver invisible using Selenium and VB?

末鹿安然 提交于 2021-02-11 12:20:48
问题 I am using Selenium WebDriver to make some automations, using chrome I can use the headless argument to hide it, but I don't know the argument to hide the Internet Explorer. Dim driver As New ChromeDriver driver.AddArgument ("headless") Dim driver As New IEDriver driver.AddArgument ("?????????????????????") Library used - A Selenium based browser automation framework for VB.Net, VBA and VBScript 回答1: Based on my searching results, it looks like Internet Explorer does not support Headless mode

Opening tabs using selenium based on user input

吃可爱长大的小学妹 提交于 2021-02-11 12:20:45
问题 I'm trying to make a script where the program takes input of multiple URLs and then opens tabs for each of them, this is what I came up with s=raw_input() l=s.split() t=len(l) for elements in l: elements = ["https://" + elements + "" for elements in l] driver = webdriver.Chrome(r"C:/Users/mynam/Desktop/WB/chromedriver.exe") driver.get("https://www.google.com") for e in elements: driver.implicitly_wait(3) driver.execute_script("window.open(e,'new window')") print "Opened in new tab" I get an

Opening tabs using selenium based on user input

百般思念 提交于 2021-02-11 12:18:38
问题 I'm trying to make a script where the program takes input of multiple URLs and then opens tabs for each of them, this is what I came up with s=raw_input() l=s.split() t=len(l) for elements in l: elements = ["https://" + elements + "" for elements in l] driver = webdriver.Chrome(r"C:/Users/mynam/Desktop/WB/chromedriver.exe") driver.get("https://www.google.com") for e in elements: driver.implicitly_wait(3) driver.execute_script("window.open(e,'new window')") print "Opened in new tab" I get an

Selenium Chrome webdriver SessionNotCreatedException

戏子无情 提交于 2021-02-11 12:13:37
问题 Using selenium & Chrome webdriver, I'm getting below exception on trying to launch. I have gone through lot of posts and tried all possible ways. I'm using compatible chrome browser and chrome drivers versions - Version 80. Java - 1.8 Windows 10 os The same test when i run on my personal computer, its working. But it's giving below error on my organization s machine. Also, no issues if I use edge drivers. org.openqa.selenium.SessionNotCreatedException: session not created disconnected: unable

selenium中的多窗口切换

那年仲夏 提交于 2021-02-11 12:13:34
在selenium中,我们会遇到一些问题,就是多窗口处理的问题,我们爬取的内容在一个新窗口上,这个时候,我们就需要先切换到这个新的窗口上,然后进行抓取内容。 如何切换呢? 首先,获取当前窗口句柄 1.元素有属性,浏览器的窗口其实也有属性的,只是你看不到,浏览器窗口的属性用句柄(handle)来识别。 2.人为操作的话,可以通过眼睛看,识别不同的窗口点击切换。但是脚本没长眼睛,它不知道你要操作哪个窗口,这时候只能句柄来判断了。 3.获取当前页面的句柄:driver.current_window_handle。 然后我们通过遍历的方式,切换到另一个窗口,上代码: from selenium import webdriver import time zhuye = obj.current_window_handle all_handles = obj.window_handles if len(all_handles)>1: for handle in all_handles: if handle != zhuye: obj.switch_to.window(handle)  这样,我们就将从当前窗口切换到新的窗口,selenium的爬虫就可以抓取新窗口上的东西了 最近看了另外一种切换窗口的办法 # 获取所有的窗口 all_h = browser.window_handles #

Optimizing python web scraping script with Selenium

不想你离开。 提交于 2021-02-11 12:04:52
问题 I'm having an issue with my web scraping script with Selenium Normally, the script can run smoothly. However, I would usually have this error within this for loop (I believe the script ran too fast before the elements can be visible): NoSuchElementException Traceback (most recent call last) <ipython-input-6-470748a6674f> in <module> 66 item_brand.append(driver.find_element_by_xpath('.//*[@id="brand"]/a/span/bdi').get_attribute('textContent')) 67 item_prices.append(driver.find_element_by_css

How to selecting option from right click menu with Selenium

橙三吉。 提交于 2021-02-11 11:53:27
问题 I'm using chrome as the driver and after double-clicking/context-clicking, the prompt window opens but the driver won't switch to the prompt window. Here is what I have tried... The page I am opening is google.com, search, then trying to right-click so i can open the results in different tabs. Thanks in advance. ....... element = driver.find_element_by_class_name("LC20lb") actionchains = ActionChains(driver) actionchains.context_click(element).perform() # Driver needs to switch to the popup

How to selecting option from right click menu with Selenium

微笑、不失礼 提交于 2021-02-11 11:53:19
问题 I'm using chrome as the driver and after double-clicking/context-clicking, the prompt window opens but the driver won't switch to the prompt window. Here is what I have tried... The page I am opening is google.com, search, then trying to right-click so i can open the results in different tabs. Thanks in advance. ....... element = driver.find_element_by_class_name("LC20lb") actionchains = ActionChains(driver) actionchains.context_click(element).perform() # Driver needs to switch to the popup