I give up, i cant find the solution, so i will ask here, thank you.
After i perform a double click i have 2 options: "drept" and "restrictie".
After pressing "drept":
\<td role="gridcell" tabindex="0" class="a-GV-cell u-tS is-changed" xpath="1" aria-labelledby="RIGHTS_ig_grid_vc_ctx RIGHTS_ig_grid_vc_cur" id="RIGHTS_ig_grid_vc_cur"\>Drept\</td\>
::before
"Drept" ==$0
After pressing "restrictie":
\<td role="gridcell" tabindex="0" class="a-GV-cell u-tS is-changed" xpath="1" aria-labelledby="RIGHTS_ig_grid_vc_ctx RIGHTS_ig_grid_vc_cur" id="RIGHTS_ig_grid_vc_cur"\>Restrictie\</td\>
::before
"Restrictie"
How can i perform the action?thank you!
didn't try because double click doesnt work on this!
Related
EDIT FROM FUTURE, MAY BE YOUR SOLUTION: The page that I was trying to deal with opens on a new tab which I've missed to notice. My driver was trying to find the element on the very first tab, that is why it was unable to locate element.
--
--
--
I tried all solutions on Stackoverflow, however still got the same problem.
I am trying to select a specific option from a dropbox. It looks like this:
click to see the dropbox.
The HTML that belongs to this dropbox is as follows:
<td ct="GLC" lsdata="{1:'STANDARD'}" id="WD18" class="lsContainerCell lsGLCTopVAlign lsContainerCellVAlign--top urLayoutDefault--grid" valign="TOP" align="left" style="white-space:normal;"><span id="WD19-r" class="lsField lsField--standalone lsField--explicitwidth lsField--hasellipsis lsField--hashelp lsField--list lsField--focus lsField--interactiontarget" aria-live="assertive" style=""><input id="WD19" ct="CB" lsdata="{2:'WD1A',3:'10',4:'2021\x2f2022',27:'WD17'}" lsevents="{Select:[{ResponseData:'delta',EnqueueCardinality:'single'},{}]}" type="text" autocomplete="off" tabindex="0" ti="0" class="lsField__input" readonly="" value="2021/2022" role="combobox" aria-haspopup="listbox" aria-readonly="false" aria-controls="WD1A" aria-expanded="false" aria-autocomplete="list" style="width:150px;" title=""><span id="WD19-btn" class="lsField__help" tabindex="-1" ti="-1" aria-hidden="true" role="button"></span></span></td>
Nothing I have tried did work because Selenium can not locate element. I've tried it with By.ID and By.XPATH. Last thing I have tried is this:
driver.find_element(By.XPATH, "/html/body/table/tbody/tr/td/div/div[1]/span/span[1]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]")
But I still got the same error for the thousandth time:
Message: no such element: Unable to locate element
Thanks in advance.
Try this Xpath, avoid absolute path (click element, get xpath -_-)
driver.find_element(By.XPATH, "//td[#ct='GLC']")
`<div id="businessCategory12">`
`<p style="margin-top: 0px;line-height:80%;margin-left:5px;font-weight: bold;color:#00004C">Business Types</p>`
`<p style="margin-top: 0px;line-height:80%;margin-left:15px;font-weight: bold;"> Minority Owned Business</p>`
`<p style="margin-top: 0px;line-height:80%;margin-left:15px;"> Black American Owned</p>`
`</div>``
I am working on a webscraping tool for a client. I need to get the text from the third paragraph above using selenium (python) but I am having a lot of trouble. The text should be "Black American Owned". I have tried the following but it keeps giving me a null value. What am I doing wrong here?
Any help or other way to get the text would be greatly greatly appreciated!
`minority = driver.find_element_by_xpath("//*[#id='businessCategory12']/p[3]")`
`minority_owned = minority.text`
Possibly the node is hidden try with textContent instead of text
minority = driver.find_element_by_xpath("//*[#id='businessCategory12']/p[3]")
minority_owned = minority.get_attribute("textContent")
<div id="businessCategory12">
<p style="margin-top: 0px;line-height:80%;margin-left:5px;font-weight: bold;color:#00004C">Business Types</p>
<p style="margin-top: 0px;line-height:80%;margin-left:15px;font-weight: bold;">Minority Owned Business</p>
<p style="margin-top: 0px;line-height:80%;margin-left:15px;">Black American Owned</p>
</div>
Just try:
//p[3]/text()
Here is a good site to play around xpath:
https://scrapinghub.github.io/xpath-playground/
Hi I'm trying to automate a process with selenium, python and GLPI, but recently I spend a lot o f time trying to select a user of a menu bar,I already did tests with linkText,cssSelector,xpath but none works for me, Maybe I'll be doing it wrong, I appreciate your help.
driver.find_element_by_xpath("//a[contains(#href,'javascript:void(0)') and contains(.,'select2-choice')]").click()
driver.find_element_by_css_selector("a[href*='select2-container select2-container-active select2-dropdown-open']").click()
driver.find_element_by_link_text("javascript:void(0)").click()
https://ibb.co/RbrXDrv that is the code source
<div class="select2-container select2-container-active select2-dropdown-open" id="s2id_dropdown__users_id_requester722037505" style="width: 80%;"> <span class="select2-chosen" id="select2-chosen-4">-----</span><abbr class="select2-search-choice-close"></abbr> <span class="select2-arrow" role="presentation"><b role="presentation"></b></span><label for="s2id_autogen4" class="select2-offscreen"></label><input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-4" id="s2id_autogen4" disabled=""></div>
thanks
Your xpath is not correct.
Try this:
driver.find_element_by_xpath("//a[#href='javascript:void(0)' and #class='select2-choice']").click()
BTW, it would be better to provide url or html, not picture.
I need to close a popup window from the website itself by pressing the "X" window on the top right. Here is the shortened, relevant part of my code:
chromedriver = r'C:\Users\do\Desktop\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
url = 'Fake.com'
browser.get(url)
browser.find_element_by_id('imgAttachmentsImg').click()
# I need to close out the window after this
The issue is that there are no unique identifiers for the "X" button itself. However, the pop up itself does have a unique identifier. I just need to be able to flow it down to the X button.
Info from the page:
1. V<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-draggable ui-resizable" tabindex="-1" role="dialog" aria-describedby="attachmentsDialogOverview" aria-labelledby="ui-id-3" style="position: absolute; height: auto; width: auto; top: 239px; left: 102px; display: block;">
2. <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
3. <span id="ui-id-3" class="ui-dialog-title">Attachments</span>
4. V<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" aria-disabled="false" title="close">
5. <span class="ui-button-icon-primary ui-icon ui-icon-closethick"</span>
6. <span class="ui-button-text">close</span></button>
I am new to using Python and Selenium. I switched over from VBA and still don't exactly understand all the syntax yet, so I do make mistakes! I did find a bandaid solution by just having sendkeys press Escape. But I am trying to actually understand how to actually solve this. I am not sure what errors I made with my solution:
browser.find_element_by_xpath("//span[#id, 'ui-id-3']/following-sibling::button").click()
Questions
Why did my solution not work?
How would I locate "ui-id-3"(on line 3) and get to the element on Line 4 to click it?
How would I locate "ui-id-3"(on line 3) and get to the element on Line 5 to click it? (just so I know how to move across multiple elements)
Relevant links I looked over:
Following-Sibling Python Selenium
Find next sibling element in Python Selenium?
Using XPath Selector 'following-sibling::text()' in Selenium (Python)
Python + Selenium WebDriver - Get div value if sibling contains string
What is the correct syntax for using a variable and following-sibling in Python Selenium?
The xpath has a problem. this should work:
browser.find_element_by_xpath("//span[#id='ui-id-3']/following-sibling::button").click()
To get to the span below it, you could use:
browser.find_element_by_xpath("//span[#id='ui-id-3']/following-sibling::button/span")
by the way, if you're more comfortable with CSS, the equivalent paths would be:
div#ui-id-3 > button
div#ui-id-3 > button span:nth-of-type(1)
I am using Anaconda2, Jupiter, and Chrome browser.
I am writing below code which is running successfully but now I want to click on button.
<a href="#" action="exportSelected" class="btn btn-default">
<i class="glyphicon glyphicon-download"></i> Export
</a>
What should I write in Python to access this?
find_element_by_partial_link_text('btn btn-default').click()
It's giving an error.
"btn btn-default" is not a link text, but class names.
You can use one of below solutions:
Locate by exact link text:
find_element_by_link_text('Export').click()
Locate by compound class name:
find_element_by_css_selector('a.btn.btn-default').click()
Locate by action attribute
find_element_by_css_selector('a[action="exportSelected"]').click()
Thank you all replying me and suggesting pyhthon doc. appreciate it.
So i have used very simple lines to get my job done.
driver.find_element_by_xpath('copy your xpath').
which is very simple
driver.find_element_by_xpath('//[#id="app_content"]/div[2]/div/div/section/div/div[2]/div[1]/div[1]/div/div[2]/a[1]').click()
driver.implicitly_wait(5)
driver.find_element_by_xpath('//[#id="export_button"]').click()