xpath

How to select an option from the dropdown menu using Selenium and Python

折月煮酒 提交于 2021-02-05 08:12:08
问题 I am trying to get the fares for all combinations of stations in Metro-North using Selenium in Python. I wanted to go to their fare page, put station names into the select fields, click on the fare button, and then copy the needed values to the dataframe. I tried all possible options to select stations from the dropdown menu but nothing works as I get the error: ElementNotInteractableException . The code I tried: driver = webdriver.Safari() driver.get('http://as0.mta.info/mnr/schedules/sched

selenium.common.exceptions.WebDriverException: Message: Failed to convert data to an object while trying to click an element with Selenium and Python

a 夏天 提交于 2021-02-05 08:09:59
问题 im trying to click a button on a page after logging in the button is the following HTML <div id="carrierDashboardControls"> <button class="yms-button-primary" ng-click="refresh()"> <t>Refresh</t> </button> <button class="yms-button-primary-alt ng-isolate-scope" ng-csv="fetchData()" lazy-load="true" csv-header="getCsvHeader" filename="carrier-dashboard.csv" field-separator=",">CSV </button> </div> there are 2 buttons in this and i want to click the one with class "yms-button-primary-alt ng

How to extract the text from the search results of duckduckgo using Selenium Python

﹥>﹥吖頭↗ 提交于 2021-02-05 08:09:12
问题 I am trying to get the link descriptions of duckduck of search results using the following: results=browser.find_elements_by_xpath("//div[@id='links']/div/div/div[2]") description=[] for result in results: description.append(result.text) I am getting the error 'list' object has no attribute 'text'. I was able to use a similar method to get the search result titles, but for some reason I am unable to extract the text from this particular xpath. 回答1: To extract the link descriptions of the

How to get all text from different elements under one div

孤人 提交于 2021-02-05 07:51:32
问题 I have problem, here is html pseudocode: <div class="content" id="ui6" role ="tabpanel"> <p> text </p> <ul> <li> text2 </li> <li> text3 </li> </ul> </div> I want to get text, text2 and text3 and print them, but I can only manage to get "text". Here is the code: List<WebElement> sectionThreeText = driver.findElements(By.cssSelector("#ui6")); for(WebElement e : sectionThreeText) { System.out.println(e.getText()); } I tried also find it by: css = "#ui6 > p ul" xpath = "//*[@id=ui6]" xpath = "//*

Python selenium to extract elements with xpath and for loop

自古美人都是妖i 提交于 2021-02-05 07:49:06
问题 I am using Python/Selenium to extract some text from a website to further sort it in Google Sheets. There are 15 headers for which I need to extract text. The text is found under each header in tag h5. Here's one extract of a header: <tr class="dayHeader"> <td colspan="7" style="padding:10px 0;"> <hr> <h5>  Tuesday - 02 February 2021</h5> </td> </tr> What I have done is the following: headers = driver.find_elements_by_tag_name('h5') results = [] for header in headers: result = header.text

Extract data from HTML table row column

不打扰是莪最后的温柔 提交于 2021-02-05 07:47:26
问题 How to extract data from HTML table in PHP. The data is in this format Table 1 <tr><td class="body" valign="top"><a href="example"><b>DATA</b></a></td><td class="body" valign="top">Data_Text</td></tr> Table 2 <tr><th><div id="Data">Data</div></th><td>Data_Text_1</td><td>Data_Text_2</td></tr> Table 3 <tr><td width="120"><a href="example" target="_blank">DATA</a></td><td>Data_Text</td></tr> I want to get the Data & Data_Text or (Data_Text_1 & Data_Text_2) from the 3 tables . I've used $html =

ElementNotInteractableException: Message: Element could not be scrolled into view using GeckoDriver Firefox with Selenium WebDriver

偶尔善良 提交于 2021-02-05 07:45:06
问题 How can I fix the error: selenium.common.exceptions.ElementNotInteractableException: Message: Element <> could not be scrolled into view error when working with Firefox via Selenium? None of the tips from the site did not help me. I tried all the solutions I could find, including through WebDriverWait and JS. One of the solutions gave: selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (568, 1215) is out of bounds of viewport width (1283) and height (699) I tried resizing the

How to get text from textnodes seperated by whitespace using Selenium and Python

♀尐吖头ヾ 提交于 2021-02-05 07:44:49
问题 I am on this page: https://fantasy.premierleague.com/statistics When you click on any "i" icon next to a player, a popup window appears. Then, i want to get the surname of the player. This is how "inspect element" looks like ("whitespace" actually appears within a box): <h2 class="ElementDialog__ElementHeading-gmefnd-2 ijAScJ"> Kevin whitespace De Bruyne What i want to do is to take the text that appears after the whitespace. I can get the full text (ie both name and surname) using this:

How get the text from the <p> tag using XPath Selenium and Python

坚强是说给别人听的谎言 提交于 2021-02-05 07:39:16
问题 I need to catch with XPath one line from a text inside a <p> . I need to store the text Content-type: text/plain; charset=us-ascii into a variable in python but i get the next error: selenium.common.exceptions.WebDriverException: Message: TypeError: Expected an element or WindowProxy, got: [object Text] {} Here is the code im trying: import selenium.webdriver as webdriver browser = webdriver.Firefox() browser.get('https://www.w3.org/Protocols/rfc1341/7_1_Text.html') foo = browser.find_element

How to locate/find element whose ID and xpath changes on every refresh - Selenium WebDriver Java

一曲冷凌霜 提交于 2021-02-05 06:33:05
问题 I am working on selenium webdriver using java, and I am facing a problem. I have a field on a page whose id and xpath changes every time that page is loaded. Like, when I open that page manually, I can see some id and xpath, but when my test run, the id, xpath has changed. Example, .//*[@id='dp1445259656810'] .//*[@id='dp1445260051638'] .//*[@id='dp1445260078674'] .//*[@id='dp1445260154173'] these are the xpaths that are created every time I refresh my page. How can I locate/find such an