find element by ul li tag in selenium - selenium-chromedriver

Trying a slightly different avenue to reach the same conclusion as my previous question. I am unable to automate a click on a tab menu on a website. I keep getting an "unable to locate element" error. I tried searching directly by both name and id, but neither attempt actually clicked on the tab (whether I used click() or submit()). Now I have been trying xpath, but it is failing as well.
the ul xpath is
//*[#id="HomeImage"]/div/div/div[1]/div/section/div[2]/div[1]/div[1]/ul
li xpath is
//*[#id="travelPlanTab"]
I tried
browser.find_element('xpath', "//[#role='tablist']/li[#id='travelPlanTab']").submit()
this failed as well.
Any suggestions?

Use OR locator
for example
Xpath[#type='' or #name='']

Related

How to stop jumping to xPath hit on search - Chrome Inspect Elements

In my work I write a lot of locators to elements on websites. So I will inspect the element and then manually construct an xPath matching it.
What is driving me crazy is that when using the ctrl+f search bar to construct/verify the locator it jumps to the first element as soon as it gets any sort of match. So if I start writing '//div' and is intending to continue it, it still jumps to the very first div in the code and the element I was trying to construct a locator for disappears from view. Or I will have to start constructing it from the back etc just so it won't find a match until I am done, which just complicates it.
Is there any way of disabling the automatic search? So that it only does the match when pressing enter, or something similar. I have looked through the settings but can't find any way.
Please help, it is driving me insane.
Was running into this same issue and found something that might help.
In Devtools > Settings > Preferences > Global > "Search as you type" checkbox.
Just uncheck that setting and the selector won't match until you hit Enter.
For more context, check out the chrome documentation page about this: https://developer.chrome.com/docs/devtools/dom/

Selenium: How to deal with web elements that get hidden when you try to inspect them? Python 3.x related

I'm about to finish developing an automated program on Python and the only thing that's stopping me it's a web element that gets immediately hidden when I try to inspect it from an OpenSea page (can't share the link here since it requires to be connected to my wallet):
So far, I have only managed to get the XPATH and the CSS_SELECTOR of this problematic element (div#tippy-298) which is the following:
button_problematic_xpath = driver.find_element(By.XPATH, '//*[#id="tippy-298"]')
button_problematic_css = driver.find_element(By.CSS_SELECTOR, '#tippy-298')
But what I need is to get the XPATH or CSS_SELECTOR of the Web Elements that button_problematic_css contains, more specifically the "Starting" and "Ending" Textboxes :
Also, just in case, the element that's on top of button_problematic_css is called "Duration", here's its XPATH:
button_duration = driver.find_element(By.XPATH, '//*[#id="duration"]').click #after clicked it deploys div#tippy-298 element
I was wondering if there could be any method to force the visibility of this button_problematic_css using the Chrome Console in the Inspection of Web Elements, or by using an specific method from Selenium on Python3.x to inmediately download all of the web elements this page has right after button_problematic_css is visible.
What I have tried so far is to manually inspect the element, by pressing Ctrl + Shift + C and and then clicking the elements contained in button_problematic_css which just ends up hiding this element before even clicking its content, the same happens when trying to display the contents of this element in the DOM of this page, it just dissapears.
I just wish my program could be capable of editing the dates in the "Starting" and "Ending" Textboxes
I guess you need to click the button to show the element. why did I guess? you need to show the url
or u can also try this code:
clickmore=WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, 'blabalabla')))
self.driver.execute_script("arguments[0].click();", clickmore)
button_duration = driver.find_element(By.XPATH, '//*[#id="duration"]').click()
After several days of working, I managed to solve this, it happened that in order to get the XPATH from these particular elements, I had to use the Chrome Console and type $('#duration').click();.
In this case, #duration is a Selector that can be used to get the web element button that allows you to edit the period of time you want to set when clicked.
I guess the general statement would be something like this:
$('#your_css_selector').click();
Now, this way I could managed to look deeper in the DOM without making them hide again.

How to check which web elements that are truly clickable?

I am experimenting with web-crawling techniques with python and selenium webdriver in win10 and firefox.
I encountered the following typical page with a pop-up box asking for consent to allowing for cookies.
https://irs.thsrc.com.tw/IMINT/
There are only the following two clickable tags in the page with the following xpaths.
//html/body/div[2]/form[1]/div[2]/div[1]/div[1]/div[1]/div[1]/span[1]/a[1]
//html/body/div[2]/form[1]/div[2]/div[1]/div[1]/div[2]/table[1]/tr[1]/td[1]/input[1]
People here suggested that I can first get an element via webdriver and then use the two methods of is_enabled() and is_displayed() to together check if the element is clickable.
However, when I get elements with the following statement:
e = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, xpath)))
I found that all elements (even those in the shadow) that I got via the above statement are both enabled and displayed.
But in fact in the browser, only the two actionable elements in the pop-up message box were clickable.
All the other elements were in the shadow and cannot be clicked (or actionable).
Can someone tell me how to get the correct information which elements are actually actionable via some API ?
Thank you very much.
Farn

Codeception can't click on element it has seen just before

Hello dear people of Stackoverflow,
currently I am writing acceptance tests with Codeception using Selenium as WebDriver module. In my test to check if our sub-navigation exists, is complete and works I struggle with the following piece of code:
$I->see('Partners');
$I->click('Partners');
all the see calls are working perfectly, but the click call fails with an ElementNotVisibleException stating that the element to be clicked is not visible, which I don't understand since the see call worked.
To make sure we're not seeing any old "Partners" string on the page but it really is the link I want to click, I changed the call by adding the a selector.
$I->see('Partners', 'a');
$I->click('Partners');
Still, I'm getting the ElementNotVisibleException from before. In the next step, I added a context to the click call to this:
$I->click('Partners', 'a');
Which made the exception disappear. Still, the click never happens, the test simply fails with the message:
Link or Button or CSS or XPath element with 'Partner' was not found.
I even used XPath in the click call like this: //a[text()='Partners'] and get the same message.
What bothers me the most with this is that the see call seems to see the link I am trying to click and moreover, even the page source and screenshot provided by Codeception after a fail contain this very link, visible and in valid HTML.
I tried to click on some other elements within the sub-navigation with the same result, while - which is even more strange - clicks on links in the main navigation seem to work just fine.
I have no idea why this doesn't work but any help is greatly appreciated.
I don't understand exactly why it happens in some cases and not others, but I've found a solution that works for me: Use CSS selectors only.
Basically in some cases (I think it has to do with clicking on div/span rather than a/button) ->see() will work with the fuzzy text string as first argument, but ->click() requires the explicit CSS selector.
So this will have the "I can see but not click" problems:
// BROKEN
$I->see("All topics", ".header-taxonomy .taxonomy-list-title");
$I->click("All topics", ".header-taxonomy .taxonomy-list-title");
But this will work:
// WORKS
$I->see("All topics", ".header-taxonomy .taxonomy-list-title");
$I->click(".header-taxonomy .taxonomy-list-title");
Obviously it's not ideal at all, partly because it requires a unique selector, but for me mostly just because it makes the tests and testing output less consistent and harder to read.
Either way, I just wanted to get this testing script finished, and now it's working, and because I'm still using ->see() with the fuzzy text locator, I'm still confident that the text is showing before I click.
Notably, this issue doesn't happen when using the PHPBrowser module, which is what tripped me up. I "upgraded" to WebDriver and found my scripts were broken in all these places due to the different behavior of ->click() (in addition to the expected need to open menus before using them, which wasn't needed in PHPBrowser)

find all elements that used a specific css selector

Trying to do some front end design work and I needed to do some debugging/testing of my css.
I know with most browser dev tools, I can click on an elements and get a full style trace.
But what I want to do is the reverse.
I know the selector and I wish to find all elements that are associated with it (simple ctrl+f not working out)
How would I go about this?
You can surely do this in the normal Javascript console with document.querySelectorAll.
So if you want to find all the elements that match body div.heading h1, do
document.querySelectorAll('body div.heading h1');
The browser console will show the elements it has found. Most also highlight them in the page when you mouseover the listing in the console.