selenium

Finding elements by CSS selector with ChromeDriver (Selenium) in Python

纵饮孤独 提交于 2021-02-08 03:01:32
问题 I'm using ChromeDriver of Selenium with Python and I'm trying to find a button on my page that has the following HTML: <input id="j_id0:SiteTemplate:j_id255:new" type="submit" name="j_id0:SiteTemplate:j_id255:new" value="New" class="kbutton-white"> The only thing I know being constant is the id and name ending with "new" and I'm trying to use the following code to identify and click that element: test_runner.driver.find_element_by_css_selector('[id*=new]').click() However, I get this error

Finding elements by CSS selector with ChromeDriver (Selenium) in Python

我的未来我决定 提交于 2021-02-08 03:00:51
问题 I'm using ChromeDriver of Selenium with Python and I'm trying to find a button on my page that has the following HTML: <input id="j_id0:SiteTemplate:j_id255:new" type="submit" name="j_id0:SiteTemplate:j_id255:new" value="New" class="kbutton-white"> The only thing I know being constant is the id and name ending with "new" and I'm trying to use the following code to identify and click that element: test_runner.driver.find_element_by_css_selector('[id*=new]').click() However, I get this error

Selenium find_elements_by_css_selector returns an empty list

拈花ヽ惹草 提交于 2021-02-07 21:37:48
问题 I'm trying to select all the ids which contain coupon-link keyword with the following script. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://udemycoupon.discountsglobal.com/coupon-category/free-2/") elems = driver.find_elements_by_css_selector('[id~=\"coupon-link\"]') print(elems) But I got an empty list [] as the result. What's wrong with my css_selector? I've tested that find_elements_by_css_selector('[id=\

Selenium find_elements_by_css_selector returns an empty list

守給你的承諾、 提交于 2021-02-07 21:37:13
问题 I'm trying to select all the ids which contain coupon-link keyword with the following script. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://udemycoupon.discountsglobal.com/coupon-category/free-2/") elems = driver.find_elements_by_css_selector('[id~=\"coupon-link\"]') print(elems) But I got an empty list [] as the result. What's wrong with my css_selector? I've tested that find_elements_by_css_selector('[id=\

Headless Google Chrome: How to prevent sites to know whether their window is focused or not

橙三吉。 提交于 2021-02-07 20:31:39
问题 Is there a way to prevent sites to know if they are visible or not? Perhaps a command line flag? I checked here but I could not find anything suitable https://peter.sh/experiments/chromium-command-line-switches/. I think they use the page visibility API: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API 回答1: If your goal is to fool the visibility API, then inject this piece of script in the related page or frame: await page.evaluate(` Object.defineProperty(window.document,

Python selenium CTRL+C closes chromedriver

北城以北 提交于 2021-02-07 20:27:06
问题 How can I catch CTRL+C (a KeyboardInterrupt) without causing the chromedriver to close. It closes the chromedriver when I run my script.py through cmd. driver = webdriver.Chrome() try: while True: #do stuff with chromedriver except KeyboardInterrupt: print "User pressed CTRL + C" #do other stuff with chromedriver It does catch the KeyboardInterrupt in my script, thus my script continues but the chromedriver also gets it and close itself. EDIT 1: The solution here doesn't work when you run the

How can i get display:none element using Selenium Webdriver c#?

吃可爱长大的小学妹 提交于 2021-02-07 17:33:16
问题 enter image description here Please provide me the scripting code in C# to get the text of the element that are marked in blue box. I am using Selenium Web driver and I want to get the value:10975 in the td tag. I tried the following code: IWebElement tableLocator = divLocator.FindElement(table); IWebElement tbodyFind = tableLocator.FindElement(tbodytag); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); wait.Until(ExpectedConditions.ElementIsVisible(trTag)); List

Download file with firefox bypassing popup : Selenium Python

社会主义新天地 提交于 2021-02-07 17:23:54
问题 I am using selenium with python to download certain files from this web page. I have been previously using set preferences to create Firefox profile, and they worked perfectly fine. In this case the download pop up opens on same page, despite given preferences it always opens pop up for action (save/open). can anybody help bypassing it and download file automatically without pop up alert ? The preference settings are: fp = webdriver.FirefoxProfile() fp.set_preference("browser.download

Selenium CSS selector for nth occurrence of td span:nth-child(2)

南笙酒味 提交于 2021-02-07 14:32:15
问题 The css selector td span:nth-child(2) means the 2nd child node span of td . I wanna choose the nth td span:nth-child(2) , something like: driver.find_element_by_css_selector("td span:nth-child(2):eq(4)") I know I can use driver.find_elements_by_css_selector("td span:nth-child(2)")[4] or xpath instead: driver.find_elements_by_xpath('(//td/span[2])[4]') I just wanna know if I can do the same thing with css selector. 回答1: You can't do this with a CSS selector. :eq() is from jQuery and not part

Selenium CSS selector for nth occurrence of td span:nth-child(2)

岁酱吖の 提交于 2021-02-07 14:27:27
问题 The css selector td span:nth-child(2) means the 2nd child node span of td . I wanna choose the nth td span:nth-child(2) , something like: driver.find_element_by_css_selector("td span:nth-child(2):eq(4)") I know I can use driver.find_elements_by_css_selector("td span:nth-child(2)")[4] or xpath instead: driver.find_elements_by_xpath('(//td/span[2])[4]') I just wanna know if I can do the same thing with css selector. 回答1: You can't do this with a CSS selector. :eq() is from jQuery and not part